summaryrefslogtreecommitdiff
path: root/ref/print.html
diff options
context:
space:
mode:
Diffstat (limited to 'ref/print.html')
-rw-r--r--ref/print.html60
1 files changed, 37 insertions, 23 deletions
diff --git a/ref/print.html b/ref/print.html
index 26ab6dbd..92648422 100644
--- a/ref/print.html
+++ b/ref/print.html
@@ -4954,12 +4954,19 @@ request interleaving.</p>
<p>This function returns immediately, with no return value.
Completion of the operation is signaled via the <em>aio</em>, and the final result
may be obtained via <a href="api/../api/aio.html#result-of-operation"><code>nng_aio_result</code></a>.</p>
+<h3 id="socket-addresses"><a class="header" href="#socket-addresses">Socket Addresses</a></h3>
+<pre><code class="language-c">nng_err nng_http_local_address(nng_http *conn, nng_sockaddr *addr);
+nng_err nng_http_remote_address(nng_http *conn, nng_sockaddr *addr);
+</code></pre>
+<p>The <a name="a040"></a><code>nng_http_local_address</code> and <a name="a041"></a><code>nng_http_remote_address</code> functions
+can be used to determine the local and remote addresses for an HTTP connection.
+This can only be done while the connection is alive.</p>
<h3 id="response-body"><a class="header" href="#response-body">Response Body</a></h3>
<h2 id="server-api"><a class="header" href="#server-api">Server API</a></h2>
<h3 id="handlers"><a class="header" href="#handlers">Handlers</a></h3>
<pre><code class="language-c">typedef struct nng_http_handler nng_http_handler;
</code></pre>
-<p>An <a name="a040"></a><code>nng_http_handler</code> encapsulates a function used used to handle
+<p>An <a name="a042"></a><code>nng_http_handler</code> encapsulates a function used used to handle
incoming requests on an HTTP server, routed based on method and URI,
and the parameters used with that function.</p>
<p>Every handler has a Request-URI to which it refers, which is determined by the <em>path</em> argument.
@@ -4986,7 +4993,7 @@ rather than just a single element.
nng_err nng_http_handler_alloc(nng_http_handler **hp, const char *path, nng_http_handler_func cb);
</code></pre>
-<p>The <a name="a041"></a><code>nng_http_handler_alloc</code> function allocates a generic handler
+<p>The <a name="a043"></a><code>nng_http_handler_alloc</code> function allocates a generic handler
which will be used to process requests coming into an HTTP server.
On success, a pointer to the handler is stored at the located pointed to by <em>hp</em>.</p>
<p>The handler function is specified by <em>cb</em>.
@@ -5020,7 +5027,7 @@ sent, if possible, and the connection will be closed.</p>
<pre><code class="language-c">nng_err nng_http_handler_alloc_directory(nng_http_handler **hp, const char *path, const char *dirname);
nng_err nng_http_handler_alloc_file(nng_http_handler **hp, const char *path, const char *filename);
</code></pre>
-<p>The <a name="a042"></a><code>nng_http_handler_alloc_directory</code> and <a name="a043"></a><code>nng_http_handler_alloc_file</code>
+<p>The <a name="a044"></a><code>nng_http_handler_alloc_directory</code> and <a name="a045"></a><code>nng_http_handler_alloc_file</code>
create handlers pre-configured to act as static content servers for either a full
directory at <em>dirname</em>, or the single file at <em>filename</em>. These support the “GET” and “HEAD”
methods, and the directory variant will dynamically generate <code>index.html</code> content based on
@@ -5031,7 +5038,7 @@ determined, the content type is set to “application/octet-stream”.</p>
<pre><code class="language-c">nng_err nng_http_handler_alloc_static(nng_http_handler **hp, const char *path,
const void *data, size_t size, const char *content_type);
</code></pre>
-<p>The <a name="a044"></a><code>nng_http_handler_alloc_static</code> function creates a handler that
+<p>The <a name="a046"></a><code>nng_http_handler_alloc_static</code> function creates a handler that
serves the content located in <em>data</em> (consisting of <em>size</em> bytes) at the URI <em>path</em>.
The <em>content_type</em> determines the “Content-Type” header. If <code>NULL</code> is specified
then a value of <code>application/octet-stream</code> is assumed.</p>
@@ -5039,7 +5046,7 @@ then a value of <code>application/octet-stream</code> is assumed.</p>
<pre><code class="language-c">nng_err nng_http_handler_alloc_redirect(nng_http_handler **hp, const char *path,
nng_http_status status, const char *location);
</code></pre>
-<p>The <a name="a045"></a><code>nng_http_handler_alloc_redirect</code> function creates a handler with
+<p>The <a name="a047"></a><code>nng_http_handler_alloc_redirect</code> function creates a handler with
a function that simply directions from the URI at <em>path</em> to the given <em>location</em>.</p>
<p>The HTTP reply it creates will be with <a href="api/../api/http.html#http-status">status code</a> <em>status</em>,
which should be a 3XX code such as 301, and a <code>Location:</code> header will contain the URL
@@ -5069,7 +5076,7 @@ created with <code>POST</code> should use <a href="api/../api/http.html#NNG_HTTP
<h3 id="collecting-request-body"><a class="header" href="#collecting-request-body">Collecting Request Body</a></h3>
<pre><code class="language-c">void nng_http_handler_collect_body(nng_http_handler *handler, bool want, size_t maxsz);
</code></pre>
-<p>The <a name="a046"></a><code>nng_http_handler_collect_body</code> function requests that HTTP server
+<p>The <a name="a048"></a><code>nng_http_handler_collect_body</code> function requests that HTTP server
framework collect any request body for the request and attach it to the
connection before calling the callback for the <em>handler</em>.</p>
<p>Subsequently the data can be retrieved by the handler from the request with the
@@ -5113,7 +5120,7 @@ create few limitations.</p>
<pre><code class="language-c">void nng_http_handler_set_data(nng_http_handler *handler, void *data,
void (*dtor)(void *));
</code></pre>
-<p>The <a name="a047"></a><code>nng_http_handler_set_data</code> function is used to set the
+<p>The <a name="a049"></a><code>nng_http_handler_set_data</code> function is used to set the
<em>data</em> argument that will be passed to the callback.</p>
<p>Additionally, when the handler is deallocated, if <em>dtor</em> is not <code>NULL</code>,
then it will be called with <em>data</em> as its argument.
@@ -5121,7 +5128,7 @@ The intended use of this function is deallocate any resources associated with <e
<h3 id="setting-the-method"><a class="header" href="#setting-the-method">Setting the Method</a></h3>
<pre><code class="language-c">void nng_http_handler_set_method(nng_http_handler *handler, const char *method);
</code></pre>
-<p>The <a name="a048"></a><code>nng_http_handler_set_method</code> function sets the <em>method</em> that the
+<p>The <a name="a050"></a><code>nng_http_handler_set_method</code> function sets the <em>method</em> that the
<em>handler</em> will be called for, such as “GET” or “POST”.
(By default the “GET” method is handled.)</p>
<p>If <em>method</em> is <code>NULL</code> the handler will be executed for all methods.
@@ -5139,7 +5146,7 @@ sent for such requests.</p>
<h3 id="filtering-by-host"><a class="header" href="#filtering-by-host">Filtering by Host</a></h3>
<pre><code class="language-c">void nng_http_handler_set_host(nng_http_handler *handler, const char *host);
</code></pre>
-<p>The <a name="a049"></a><code>nng_http_handler_set_host</code> function is used to limit the scope of the
+<p>The <a name="a051"></a><code>nng_http_handler_set_host</code> function is used to limit the scope of the
<em>handler</em> so that it will only be called when the specified <em>host</em> matches
the value of the <code>Host:</code> HTTP header.</p>
<p>This can be used to create servers with different content for different virtual hosts.</p>
@@ -5154,10 +5161,15 @@ exactly the value of the <code>Host</code> header sent by the client.
<p>The port number may be ignored; at present the HTTP server framework
does not support a single server listening on different ports concurrently.</p>
</div>
+<h3 id="detecting-addresses"><a class="header" href="#detecting-addresses">Detecting Addresses</a></h3>
+<p>The <a href="api/../api/http.html#socket-addresses"><code>nng_http_local_address</code></a> and <a href="api/../api/http.html#socket-addresses"><code>nng_http_remote_address</code></a> functions
+can be used to determine the local and remote addresses for an HTTP connection
+on the server side (in a handler) just like the can be for HTTP clients
+This can be useful to provide different handling behaviors based on network identity.</p>
<h3 id="handling-an-entire-tree"><a class="header" href="#handling-an-entire-tree">Handling an Entire Tree</a></h3>
<pre><code class="language-c">void nng_http_handler_set_tree(nng_http_handler *handler);
</code></pre>
-<p>The <a name="a050"></a><code>nng_http_handler_set_tree</code> function causes the <em>handler</em> to be matched if the request URI sent
+<p>The <a name="a052"></a><code>nng_http_handler_set_tree</code> function causes the <em>handler</em> to be matched if the request URI sent
by the client is a logical child of the path for <em>handler</em>, and no more specific
<em>handler</em> has been registered.</p>
<p>This is useful in cases when the handler would like to examine the entire path
@@ -5177,7 +5189,7 @@ It can also provide a logical fallback instead of relying on a 404 error code.</
</code></pre>
<p>Normally the server will send any attached response, but there are circumstances where
a response must be sent manually, such as when <a href="api/../api/http.html#hijacking-connections">hijacking</a> a connection.</p>
-<p>In such a case, <a name="a051"></a><code>nng_http_write_response</code> can be called, which will send the response and any attached data, asynchronously
+<p>In such a case, <a name="a053"></a><code>nng_http_write_response</code> can be called, which will send the response and any attached data, asynchronously
using the <a href="api/../api/aio.html#asynchronous-io-handle"><code>nng_aio</code></a> <em>aio</em>.</p>
<p>By default, for <code>HTTP/1.1</code> connections, the connection is kept open, and
will be reused to receive new requests. For <code>HTTP/1.0</code>, or if the client has requested
@@ -8743,23 +8755,25 @@ named pipes, <a href="tran/ipc.html#a004">1</a><br/>
<code>nng_http_get_reason</code>, <a href="api/http.html#a011">1</a><br/>
<code>nng_http_get_status</code>, <a href="api/http.html#a009">1</a><br/>
<code>nng_http_get_version</code>, <a href="api/http.html#a008">1</a><br/>
-<code>nng_http_handler</code>, <a href="api/http.html#a040">1</a><br/>
-<code>nng_http_handler_alloc</code>, <a href="api/http.html#a041">1</a><br/>
-<code>nng_http_handler_alloc_directory</code>, <a href="api/http.html#a042">1</a><br/>
-<code>nng_http_handler_alloc_file</code>, <a href="api/http.html#a043">1</a><br/>
-<code>nng_http_handler_alloc_redirect</code>, <a href="api/http.html#a045">1</a><br/>
-<code>nng_http_handler_alloc_static</code>, <a href="api/http.html#a044">1</a><br/>
-<code>nng_http_handler_collect_body</code>, <a href="api/http.html#a046">1</a><br/>
-<code>nng_http_handler_set_data</code>, <a href="api/http.html#a047">1</a><br/>
-<code>nng_http_handler_set_host</code>, <a href="api/http.html#a049">1</a><br/>
-<code>nng_http_handler_set_method</code>, <a href="api/http.html#a048">1</a><br/>
-<code>nng_http_handler_set_tree</code>, <a href="api/http.html#a050">1</a><br/>
+<code>nng_http_handler</code>, <a href="api/http.html#a042">1</a><br/>
+<code>nng_http_handler_alloc</code>, <a href="api/http.html#a043">1</a><br/>
+<code>nng_http_handler_alloc_directory</code>, <a href="api/http.html#a044">1</a><br/>
+<code>nng_http_handler_alloc_file</code>, <a href="api/http.html#a045">1</a><br/>
+<code>nng_http_handler_alloc_redirect</code>, <a href="api/http.html#a047">1</a><br/>
+<code>nng_http_handler_alloc_static</code>, <a href="api/http.html#a046">1</a><br/>
+<code>nng_http_handler_collect_body</code>, <a href="api/http.html#a048">1</a><br/>
+<code>nng_http_handler_set_data</code>, <a href="api/http.html#a049">1</a><br/>
+<code>nng_http_handler_set_host</code>, <a href="api/http.html#a051">1</a><br/>
+<code>nng_http_handler_set_method</code>, <a href="api/http.html#a050">1</a><br/>
+<code>nng_http_handler_set_tree</code>, <a href="api/http.html#a052">1</a><br/>
<code>nng_http_hijack</code>, <a href="api/http.html#a027">1</a><br/>
+<code>nng_http_local_address</code>, <a href="api/http.html#a040">1</a><br/>
<code>nng_http_next_header</code>, <a href="api/http.html#a014">1</a><br/>
<code>nng_http_peer_cert</code>, <a href="api/http.html#a028">1</a><br/>
<code>nng_http_read</code>, <a href="api/http.html#a023">1</a><br/>
<code>nng_http_read_all</code>, <a href="api/http.html#a025">1</a><br/>
<code>nng_http_read_response</code>, <a href="api/http.html#a037">1</a><br/>
+<code>nng_http_remote_address</code>, <a href="api/http.html#a041">1</a><br/>
<code>nng_http_reset</code>, <a href="api/http.html#a022">1</a><br/>
<code>nng_http_set_body</code>, <a href="api/http.html#a019">1</a><br/>
<code>nng_http_set_header</code>, <a href="api/http.html#a016">1</a><br/>
@@ -8772,7 +8786,7 @@ named pipes, <a href="tran/ipc.html#a004">1</a><br/>
<code>nng_http_write</code>, <a href="api/http.html#a024">1</a><br/>
<code>nng_http_write_all</code>, <a href="api/http.html#a026">1</a><br/>
<code>nng_http_write_request</code>, <a href="api/http.html#a036">1</a><br/>
-<code>nng_http_write_response</code>, <a href="api/http.html#a051">1</a><br/>
+<code>nng_http_write_response</code>, <a href="api/http.html#a053">1</a><br/>
<code>nng_id_alloc</code>, <a href="api/id_map.html#a006">1</a><br/>
<code>nng_id_get</code>, <a href="api/id_map.html#a005">1</a><br/>
<code>nng_id_map</code>, <a href="api/id_map.html#a001">1</a><br/>