tiny_httpd/0.1/tiny_httpd/Tiny_httpd/Response/index.html
2019-11-18 23:19:27 -06:00

2 lines
No EOL
7.1 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>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> &#x00BB; <a href="../index.html">Tiny_httpd</a> &#x00BB; 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>?&#8288;headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>&#45;&gt;</span> <span>code:<a href="../Response_code/index.html#type-t">Response_code.t</a></span> <span>&#45;&gt;</span> string <span>&#45;&gt;</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>&quot;&quot;</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>?&#8288;headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>&#45;&gt;</span> <span>code:<a href="../Response_code/index.html#type-t">Response_code.t</a></span> <span>&#45;&gt;</span> <a href="../index.html#type-byte_stream">byte_stream</a> <span>&#45;&gt;</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>?&#8288;headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>&#45;&gt;</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>&#45;&gt;</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>?&#8288;headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>&#45;&gt;</span> <span><span>(string, <a href="../Response_code/index.html#type-t">Response_code.t</a> * string)</span> Pervasives.result</span> <span>&#45;&gt;</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>?&#8288;headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>&#45;&gt;</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>&#45;&gt;</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>?&#8288;headers:<a href="../Headers/index.html#type-t">Headers.t</a></span> <span>&#45;&gt;</span> <span>code:int</span> <span>&#45;&gt;</span> <span><span>(<span class="type-var">'a</span>, unit, string, <a href="index.html#type-t">t</a>)</span> Pervasives.format4</span> <span>&#45;&gt;</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 &quot;oh noes, %s not found&quot; &quot;waldo&quot;</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>&#45;&gt;</span> <span><span>(<span class="type-var">'a</span>, unit, string, <span class="type-var">'b</span>)</span> Pervasives.format4</span> <span>&#45;&gt;</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 &quot;oh noes, %s not found&quot; &quot;waldo&quot;; 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>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> unit</code></dt><dd><p>Pretty print the response.</p></dd></dl></div></body></html>