mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2026-01-26 11:24:50 -05:00
2 lines
No EOL
7.1 KiB
HTML
2 lines
No EOL
7.1 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Response (tiny_httpd.Tiny_httpd.Response)</title><link rel="stylesheet" href="../../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc %%VERSION%%"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> – <a href="../../index.html">tiny_httpd</a> » <a href="../index.html">Tiny_httpd</a> » Response</nav><h1>Module <code>Tiny_httpd.Response</code></h1></header><dl><dt class="spec type" id="type-body"><a href="#type-body" class="anchor"></a><code><span class="keyword">type</span> body</code> = <code>[ </code><table class="variant"><tr id="type-body.String" class="anchored"><td class="def constructor"><a href="#type-body.String" class="anchor"></a><code>| </code><code>`String <span class="keyword">of</span> string</code></td></tr><tr id="type-body.Stream" class="anchored"><td class="def constructor"><a href="#type-body.Stream" class="anchor"></a><code>| </code><code>`Stream <span class="keyword">of</span> <a href="../index.html#type-byte_stream">byte_stream</a></code></td></tr></table><code> ]</code></dt><dd><p>Body of a response, either as a simple string, or a stream of bytes.</p></dd></dl><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> t</code><code> = </code><code>{</code><table class="record"><tr id="type-t.code" class="anchored"><td class="def field"><a href="#type-t.code" class="anchor"></a><code>code : <a href="../Response_code/index.html#type-t">Response_code.t</a>;</code></td><td class="doc"><p>HTTP response code. See <a href="../Response_code/index.html"><code>Response_code</code></a>.</p></td></tr><tr id="type-t.headers" class="anchored"><td class="def field"><a href="#type-t.headers" class="anchor"></a><code>headers : <a href="../Headers/index.html#type-t">Headers.t</a>;</code></td><td class="doc"><p>Headers of the reply. Some will be set by <code>Tiny_httpd</code> automatically.</p></td></tr><tr id="type-t.body" class="anchored"><td class="def field"><a href="#type-t.body" class="anchor"></a><code>body : <a href="index.html#type-body">body</a>;</code></td><td class="doc"><p>Body of the response. Can be empty.</p></td></tr></table><code>}</code></dt><dd><p>A response to send back to a client.</p></dd></dl><dl><dt class="spec value" id="val-make_raw"><a href="#val-make_raw" class="anchor"></a><code><span class="keyword">val</span> make_raw : <span>?⁠headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>-></span> <span>code:<a href="../Response_code/index.html#type-t">Response_code.t</a></span> <span>-></span> string <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p>Make a response from its raw components, with a string body. Use <code>""</code> to not send a body at all.</p></dd></dl><dl><dt class="spec value" id="val-make_raw_stream"><a href="#val-make_raw_stream" class="anchor"></a><code><span class="keyword">val</span> make_raw_stream : <span>?⁠headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>-></span> <span>code:<a href="../Response_code/index.html#type-t">Response_code.t</a></span> <span>-></span> <a href="../index.html#type-byte_stream">byte_stream</a> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p>Same as <a href="index.html#val-make_raw"><code>make_raw</code></a> but with a stream body. The body will be sent with the chunked transfer-encoding.</p></dd></dl><dl><dt class="spec value" id="val-make"><a href="#val-make" class="anchor"></a><code><span class="keyword">val</span> make : <span>?⁠headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>-></span> <span><span>(<a href="index.html#type-body">body</a>, <a href="../Response_code/index.html#type-t">Response_code.t</a> * string)</span> Pervasives.result</span> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>make r</code> turns a result into a response.</p><ul><li><code>make (Ok body)</code> replies with <code>200</code> and the body.</li><li><code>make (Error (code,msg))</code> replies with the given error code and message as body.</li></ul></dd></dl><dl><dt class="spec value" id="val-make_string"><a href="#val-make_string" class="anchor"></a><code><span class="keyword">val</span> make_string : <span>?⁠headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>-></span> <span><span>(string, <a href="../Response_code/index.html#type-t">Response_code.t</a> * string)</span> Pervasives.result</span> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p>Same as <a href="index.html#val-make"><code>make</code></a> but with a string body.</p></dd></dl><dl><dt class="spec value" id="val-make_stream"><a href="#val-make_stream" class="anchor"></a><code><span class="keyword">val</span> make_stream : <span>?⁠headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>-></span> <span><span>(<a href="../index.html#type-byte_stream">byte_stream</a>, <a href="../Response_code/index.html#type-t">Response_code.t</a> * string)</span> Pervasives.result</span> <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p>Same as <a href="index.html#val-make"><code>make</code></a> but with a stream body.</p></dd></dl><dl><dt class="spec value" id="val-fail"><a href="#val-fail" class="anchor"></a><code><span class="keyword">val</span> fail : <span>?⁠headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>-></span> <span>code:int</span> <span>-></span> <span><span>(<span class="type-var">'a</span>, unit, string, <a href="index.html#type-t">t</a>)</span> Pervasives.format4</span> <span>-></span> <span class="type-var">'a</span></code></dt><dd><p>Make the current request fail with the given code and message. Example: <code>fail ~code:404 "oh noes, %s not found" "waldo"</code>.</p></dd></dl><dl><dt class="spec value" id="val-fail_raise"><a href="#val-fail_raise" class="anchor"></a><code><span class="keyword">val</span> fail_raise : <span>code:int</span> <span>-></span> <span><span>(<span class="type-var">'a</span>, unit, string, <span class="type-var">'b</span>)</span> Pervasives.format4</span> <span>-></span> <span class="type-var">'a</span></code></dt><dd><p>Similar to <a href="index.html#val-fail"><code>fail</code></a> but raises an exception that exits the current handler. This should not be used outside of a (path) handler. Example: <code>fail_raise ~code:404 "oh noes, %s not found" "waldo"; never_executed()</code></p></dd></dl><dl><dt class="spec value" id="val-pp"><a href="#val-pp" class="anchor"></a><code><span class="keyword">val</span> pp : Format.formatter <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p>Pretty print the response.</p></dd></dl></div></body></html> |