tiny_httpd/dev/tiny_httpd/Tiny_httpd_server/Request/index.html
2023-05-24 19:48:57 +00:00

2 lines
No EOL
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Request (tiny_httpd.Tiny_httpd_server.Request)</title><link rel="stylesheet" href="../../../_odoc_support/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../_odoc_support/highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">tiny_httpd</a> &#x00BB; <a href="../index.html">Tiny_httpd_server</a> &#x00BB; Request</nav><header class="odoc-preamble"><h1>Module <code><span>Tiny_httpd_server.Request</span></code></h1></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> <span>'body t</span></span><span> = <span class="keyword">private</span> </span><span>{</span></code><ol><li id="type-t.meth" class="def record field anchored"><a href="#type-t.meth" class="anchor"></a><code><span>meth : <a href="../Meth/index.html#type-t">Meth.t</a>;</span></code></li><li id="type-t.host" class="def record field anchored"><a href="#type-t.host" class="anchor"></a><code><span>host : string;</span></code></li><li id="type-t.headers" class="def record field anchored"><a href="#type-t.headers" class="anchor"></a><code><span>headers : <a href="../Headers/index.html#type-t">Headers.t</a>;</span></code></li><li id="type-t.http_version" class="def record field anchored"><a href="#type-t.http_version" class="anchor"></a><code><span>http_version : int * int;</span></code></li><li id="type-t.path" class="def record field anchored"><a href="#type-t.path" class="anchor"></a><code><span>path : string;</span></code></li><li id="type-t.path_components" class="def record field anchored"><a href="#type-t.path_components" class="anchor"></a><code><span>path_components : <span>string list</span>;</span></code></li><li id="type-t.query" class="def record field anchored"><a href="#type-t.query" class="anchor"></a><code><span>query : <span><span>(string * string)</span> list</span>;</span></code></li><li id="type-t.body" class="def record field anchored"><a href="#type-t.body" class="anchor"></a><code><span>body : <span class="type-var">'body</span>;</span></code></li><li id="type-t.start_time" class="def record field anchored"><a href="#type-t.start_time" class="anchor"></a><code><span>start_time : float;</span></code><div class="def-doc"><span class="comment-delim">(*</span><p>Obtained via <code>get_time_s</code> in <a href="../index.html#val-create"><code>create</code></a></p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.11</li></ul><span class="comment-delim">*)</span></div></li></ol><code><span>}</span></code></div><div class="spec-doc"><p>A request with method, path, host, headers, and a body, sent by a client.</p><p>The body is polymorphic because the request goes through several transformations. First it has no body, as only the request and headers are read; then it has a stream body; then the body might be entirely read as a string via <a href="#val-read_body_full"><code>read_body_full</code></a>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.6 The field [query] was added and contains the query parameters in [&quot;?foo=bar,x=y&quot;]</li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.6 The field [path_components] is the part of the path that precedes [query] and is split on [&quot;/&quot;].</li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.11 the type is a private alias</li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.11 the field [start_time] was added</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pp"><a href="#val-pp" class="anchor"></a><code><span><span class="keyword">val</span> pp : <span><span class="xref-unresolved">Stdlib</span>.Format.formatter <span class="arrow">&#45;&gt;</span></span> <span><span>string <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Pretty print the request and its body</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pp_"><a href="#val-pp_" class="anchor"></a><code><span><span class="keyword">val</span> pp_ : <span><span class="xref-unresolved">Stdlib</span>.Format.formatter <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Pretty print the request without its body</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-headers"><a href="#val-headers" class="anchor"></a><code><span><span class="keyword">val</span> headers : <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="../Headers/index.html#type-t">Headers.t</a></span></code></div><div class="spec-doc"><p>List of headers of the request, including <code>&quot;Host&quot;</code></p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_header"><a href="#val-get_header" class="anchor"></a><code><span><span class="keyword">val</span> get_header : <span>?f:<span>(<span>string <span class="arrow">&#45;&gt;</span></span> string)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span>string option</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_header_int"><a href="#val-get_header_int" class="anchor"></a><code><span><span class="keyword">val</span> get_header_int : <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span>int option</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set_header"><a href="#val-set_header" class="anchor"></a><code><span><span class="keyword">val</span> set_header : <span>string <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>set_header k v req</code> sets <code>k: v</code> in the request <code>req</code>'s headers.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-update_headers"><a href="#val-update_headers" class="anchor"></a><code><span><span class="keyword">val</span> update_headers : <span><span>(<span><a href="../Headers/index.html#type-t">Headers.t</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Headers/index.html#type-t">Headers.t</a>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Modify headers</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.11</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set_body"><a href="#val-set_body" class="anchor"></a><code><span><span class="keyword">val</span> set_body : <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>set_body b req</code> returns a new query whose body is <code>b</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.11</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-host"><a href="#val-host" class="anchor"></a><code><span><span class="keyword">val</span> host : <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Host field of the request. It also appears in the headers.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-meth"><a href="#val-meth" class="anchor"></a><code><span><span class="keyword">val</span> meth : <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="../Meth/index.html#type-t">Meth.t</a></span></code></div><div class="spec-doc"><p>Method for the request.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-path"><a href="#val-path" class="anchor"></a><code><span><span class="keyword">val</span> path : <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Request path.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-query"><a href="#val-query" class="anchor"></a><code><span><span class="keyword">val</span> query : <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(string * string)</span> list</span></span></code></div><div class="spec-doc"><p>Decode the query part of the <a href="#val-path"><code>path</code></a> field</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.4</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-body"><a href="#val-body" class="anchor"></a><code><span><span class="keyword">val</span> body : <span><span><span class="type-var">'b</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span></span></code></div><div class="spec-doc"><p>Request body, possibly empty.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-start_time"><a href="#val-start_time" class="anchor"></a><code><span><span class="keyword">val</span> start_time : <span><span><span class="type-var">_</span> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> float</span></code></div><div class="spec-doc"><p>time stamp (from <code>Unix</code>.gettimeofday) after parsing the first line of the request</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.11</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-limit_body_size"><a href="#val-limit_body_size" class="anchor"></a><code><span><span class="keyword">val</span> limit_body_size : <span>max_size:int <span class="arrow">&#45;&gt;</span></span> <span><span><a href="../index.html#type-byte_stream">byte_stream</a> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><a href="../index.html#type-byte_stream">byte_stream</a> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Limit the body size to <code>max_size</code> bytes, or return a <code>413</code> error.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 0.3</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-read_body_full"><a href="#val-read_body_full" class="anchor"></a><code><span><span class="keyword">val</span> read_body_full : <span>?buf_size:int <span class="arrow">&#45;&gt;</span></span> <span><span><a href="../index.html#type-byte_stream">byte_stream</a> <a href="#type-t">t</a></span> <span class="arrow">&#45;&gt;</span></span> <span>string <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p>Read the whole body into a string. Potentially blocking.</p><ul class="at-tags"><li class="parameter"><span class="at-tag">parameter</span> <span class="value">buf_size</span> <p>initial size of underlying buffer (since 0.11)</p></li></ul></div></div></div></body></html>