ocaml-opentelemetry/cohttp-lwt/Cohttp_lwt/Make_server/index.html
2025-01-31 01:39:34 +00:00

47 lines
15 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>Make_server (cohttp-lwt.Cohttp_lwt.Make_server)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 2.4.4"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../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">cohttp-lwt</a> &#x00BB; <a href="../index.html">Cohttp_lwt</a> &#x00BB; Make_server</nav><header class="odoc-preamble"><h1>Module <code><span>Cohttp_lwt.Make_server</span></code></h1></header><nav class="odoc-toc"><ul><li><a href="#parameters">Parameters</a></li><li><a href="#signature">Signature</a></li></ul></nav><div class="odoc-content"><h2 id="parameters"><a href="#parameters" class="anchor"></a>Parameters</h2><div class="odoc-spec"><div class="spec parameter anchored" id="argument-1-IO"><a href="#argument-1-IO" class="anchor"></a><code><span><span class="keyword">module</span> </span><span><a href="argument-1-IO/index.html">IO</a></span><span> : <a href="../S/module-type-IO/index.html">S.IO</a></span></code></div></div><h2 id="signature"><a href="#signature" class="anchor"></a>Signature</h2><div class="odoc-spec"><div class="spec module anchored" id="module-IO"><a href="#module-IO" class="anchor"></a><code><span><span class="keyword">module</span> IO</span><span> = <a href="argument-1-IO/index.html">IO</a></span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-conn"><a href="#type-conn" class="anchor"></a><code><span><span class="keyword">type</span> conn</span><span> = <a href="argument-1-IO/index.html#type-conn">IO.conn</a> * <a href="../../../cohttp/Cohttp/Connection/index.html#type-t">Cohttp.Connection.t</a></span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-response_action"><a href="#type-response_action" class="anchor"></a><code><span><span class="keyword">type</span> response_action</span><span> = </span><span>[ </span></code><ol><li id="type-response_action.Expert" class="def variant constructor anchored"><a href="#type-response_action.Expert" class="anchor"></a><code><span>| </span><span>`Expert <span class="keyword">of</span> <a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <span>(<span><a href="argument-1-IO/index.html#type-ic">IO.ic</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="argument-1-IO/index.html#type-oc">IO.oc</a> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span>)</span></span></code></li><li id="type-response_action.Response" class="def variant constructor anchored"><a href="#type-response_action.Response" class="anchor"></a><code><span>| </span><span>`Response <span class="keyword">of</span> <a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <a href="../Body/index.html#type-t">Body.t</a></span></code></li></ol><code><span> ]</span></code></div><div class="spec-doc"><p>A request handler can respond in two ways:</p><ul><li>Using <code>`Response</code>, with a <a href="../../../cohttp/Cohttp/Response/index.html#type-t"><code>Response.t</code></a> and a <a href="../Body/index.html#type-t"><code>Body.t</code></a>.</li><li>Using <code>`Expert</code>, with a <a href="../../../cohttp/Cohttp/Response/index.html#type-t"><code>Response.t</code></a> and an IO function that is expected to write the response body. The IO function has access to the underlying <a href="argument-1-IO/index.html#type-ic"><code>IO.ic</code></a> and <a href="argument-1-IO/index.html#type-oc"><code>IO.oc</code></a>, which allows writing a response body more efficiently, stream a response or to switch protocols entirely (e.g. websockets). Processing of pipelined requests continue after the <code>unitLwt.t</code> is resolved. The connection can be closed by closing the <a href="argument-1-IO/index.html#type-ic"><code>IO.ic</code></a>.</li></ul></div></div><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> t</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-make_response_action"><a href="#val-make_response_action" class="anchor"></a><code><span><span class="keyword">val</span> make_response_action :
<span><span class="optlabel">?conn_closed</span>:<span>(<span><a href="#type-conn">conn</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">callback</span>:<span>(<span><a href="#type-conn">conn</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../../../cohttp/Cohttp/Request/index.html#type-t">Cohttp.Request.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Body/index.html#type-t">Body.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-response_action">response_action</a> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-make_expert"><a href="#val-make_expert" class="anchor"></a><code><span><span class="keyword">val</span> make_expert :
<span><span class="optlabel">?conn_closed</span>:<span>(<span><a href="#type-conn">conn</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">callback</span>:
<span>(<span><a href="#type-conn">conn</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../../../cohttp/Cohttp/Request/index.html#type-t">Cohttp.Request.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Body/index.html#type-t">Body.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span>(<a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <span>(<span><a href="argument-1-IO/index.html#type-ic">IO.ic</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="argument-1-IO/index.html#type-oc">IO.oc</a> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span>)</span>)</span> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-make"><a href="#val-make" class="anchor"></a><code><span><span class="keyword">val</span> make :
<span><span class="optlabel">?conn_closed</span>:<span>(<span><a href="#type-conn">conn</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">callback</span>:
<span>(<span><a href="#type-conn">conn</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../../../cohttp/Cohttp/Request/index.html#type-t">Cohttp.Request.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Body/index.html#type-t">Body.t</a> <span class="arrow">&#45;&gt;</span></span> <span><span>(<a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <a href="../Body/index.html#type-t">Body.t</a>)</span> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-resolve_local_file"><a href="#val-resolve_local_file" class="anchor"></a><code><span><span class="keyword">val</span> resolve_local_file : <span><span class="label">docroot</span>:string <span class="arrow">&#45;&gt;</span></span> <span><span class="label">uri</span>:<a href="../../../uri/Uri/index.html#type-t">Uri.t</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Resolve a URI and a docroot into a concrete local filename.</p><p>Deprecated. Please use Cohttp.Path.resolve_local_file.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-respond"><a href="#val-respond" class="anchor"></a><code><span><span class="keyword">val</span> respond :
<span><span class="optlabel">?headers</span>:<a href="../../../cohttp/Cohttp/Header/index.html#type-t">Cohttp.Header.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?flush</span>:bool <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">status</span>:<a href="../../../cohttp/Cohttp/Code/index.html#type-status_code">Cohttp.Code.status_code</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">body</span>:<a href="../Body/index.html#type-t">Body.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<span><span>(<a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <a href="../Body/index.html#type-t">Body.t</a>)</span> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p><code>respond ?headers ?flush ~status ~body</code> will respond to an HTTP request with the given <code>status</code> code and response <code>body</code>. If <code>flush</code> is true, then every response chunk will be flushed to the network rather than being buffered. <code>flush</code> is true by default. The transfer encoding will be detected from the <code>body</code> value and set to chunked encoding if it cannot be determined immediately. You can override the encoding by supplying an appropriate <code>Content-length</code> or <code>Transfer-encoding</code> in the <code>headers</code> parameter.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-respond_string"><a href="#val-respond_string" class="anchor"></a><code><span><span class="keyword">val</span> respond_string :
<span><span class="optlabel">?flush</span>:bool <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?headers</span>:<a href="../../../cohttp/Cohttp/Header/index.html#type-t">Cohttp.Header.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">status</span>:<a href="../../../cohttp/Cohttp/Code/index.html#type-status_code">Cohttp.Code.status_code</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">body</span>:string <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<span><span>(<a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <a href="../Body/index.html#type-t">Body.t</a>)</span> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-respond_error"><a href="#val-respond_error" class="anchor"></a><code><span><span class="keyword">val</span> respond_error :
<span><span class="optlabel">?headers</span>:<a href="../../../cohttp/Cohttp/Header/index.html#type-t">Cohttp.Header.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?status</span>:<a href="../../../cohttp/Cohttp/Code/index.html#type-status_code">Cohttp.Code.status_code</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">body</span>:string <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<span><span>(<a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <a href="../Body/index.html#type-t">Body.t</a>)</span> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-respond_redirect"><a href="#val-respond_redirect" class="anchor"></a><code><span><span class="keyword">val</span> respond_redirect :
<span><span class="optlabel">?headers</span>:<a href="../../../cohttp/Cohttp/Header/index.html#type-t">Cohttp.Header.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">uri</span>:<a href="../../../uri/Uri/index.html#type-t">Uri.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<span><span>(<a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <a href="../Body/index.html#type-t">Body.t</a>)</span> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-respond_need_auth"><a href="#val-respond_need_auth" class="anchor"></a><code><span><span class="keyword">val</span> respond_need_auth :
<span><span class="optlabel">?headers</span>:<a href="../../../cohttp/Cohttp/Header/index.html#type-t">Cohttp.Header.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">auth</span>:<a href="../../../cohttp/Cohttp/Auth/index.html#type-challenge">Cohttp.Auth.challenge</a> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<span><span>(<a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <a href="../Body/index.html#type-t">Body.t</a>)</span> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-respond_not_found"><a href="#val-respond_not_found" class="anchor"></a><code><span><span class="keyword">val</span> respond_not_found :
<span><span class="optlabel">?uri</span>:<a href="../../../uri/Uri/index.html#type-t">Uri.t</a> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<span><span>(<a href="../../../cohttp/Cohttp/Response/index.html#type-t">Cohttp.Response.t</a> * <a href="../Body/index.html#type-t">Body.t</a>)</span> <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-callback"><a href="#val-callback" class="anchor"></a><code><span><span class="keyword">val</span> callback : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="argument-1-IO/index.html#type-conn">IO.conn</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="argument-1-IO/index.html#type-ic">IO.ic</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="argument-1-IO/index.html#type-oc">IO.oc</a> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../../../lwt/Lwt/index.html#type-t">Lwt.t</a></span></span></code></div></div></div></body></html>