ocaml-opentelemetry/cohttp-lwt/Cohttp_lwt/S/index.html
2025-05-27 13:51:07 +00:00

9 lines
7 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>S (cohttp-lwt.Cohttp_lwt.S)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.0.0"/><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">Index</a> &#x00BB; <a href="../../index.html">cohttp-lwt</a> &#x00BB; <a href="../index.html">Cohttp_lwt</a> &#x00BB; S</nav><header class="odoc-preamble"><h1>Module <code><span>Cohttp_lwt.S</span></code></h1><p>Portable Lwt implementation of HTTP client and server, without depending on a particular I/O implementation. The various <code>Make</code> functors must be instantiated by an implementation that provides a concrete IO monad.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-IO"><a href="#module-type-IO" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-IO/index.html">IO</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>The IO module is specialized for the <code>Lwt</code> monad.</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-Net"><a href="#module-type-Net" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-Net/index.html">Net</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>The <code>Net</code> module type defines how to connect to a remote node and close the resulting channels to clean up.</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-Sleep"><a href="#module-type-Sleep" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-Sleep/index.html">Sleep</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>This is compatible with <code>Mirage_time.S</code>. It may be satisfied by mirage-time-unix <code>Time</code> or <code>Mirage_time</code>.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-call"><a href="#type-call" class="anchor"></a><code><span><span class="keyword">type</span> call</span><span> =
<span><span class="optlabel">?headers</span>:<a href="../../../http/Http/Header/index.html#type-t">Http.Header.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?body</span>:<a href="../Body/index.html#type-t">Body.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?absolute_form</span>:bool <span class="arrow">&#45;&gt;</span></span>
<span><a href="../../../http/Http/Method/index.html#type-t">Http.Method.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../../../uri/Uri/index.html#type-t">Uri.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></code></div><div class="spec-doc"><p><code>call ?headers ?body method uri</code> Function type used to handle http requests</p><ul class="at-tags"><li class="returns"><span class="at-tag">returns</span> <p><code>(response, response_body)</code> <code>response_body</code> is not buffered, but stays on the wire until consumed. It must therefore be consumed in a timely manner. Otherwise the connection would stay open and a file descriptor leak may be caused. Following responses would get blocked. Functions in the <a href="../Body/index.html"><code>Body</code></a> module can be used to consume <code>response_body</code>. Use <a href="../Body/index.html#val-drain_body"><code>Body.drain_body</code></a> if you don't consume the body by other means.</p></li></ul><p>Leaks are detected by the GC and logged as debug messages, these can be enabled activating the debug logging. For example, this can be done as follows in <code>cohttp-lwt-unix</code></p><pre class="language-ocaml"><code> Cohttp_lwt_unix.Debug.activate_debug ();
Logs.set_level (Some Logs.Warning)</code></pre><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>{!Connection.Retry}</code> <p>on recoverable errors like the remote endpoint closing the connection gracefully. Even non-idempotent requests are guaranteed to not have been processed by the remote endpoint and should be retried. But beware that a <code>`Stream</code> <code>body</code> may have been consumed.</p></li></ul></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-Connection"><a href="#module-type-Connection" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-Connection/index.html">Connection</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>The <code>Connection</code> module handles a single, possibly pipelined, http connection.</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-Connection_cache"><a href="#module-type-Connection_cache" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-Connection_cache/index.html">Connection_cache</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>A <code>Connection_cache</code> handles http requests. It not necessarily caches connections.</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-Client"><a href="#module-type-Client" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-Client/index.html">Client</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>The <code>Client</code> module is a collection of convenience functions for constructing and processing requests.</p></div></div><div class="odoc-spec"><div class="spec module-type anchored" id="module-type-Server"><a href="#module-type-Server" class="anchor"></a><code><span><span class="keyword">module</span> <span class="keyword">type</span> <a href="module-type-Server/index.html">Server</a></span><span> = <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>The <code>Server</code> module implements a pipelined HTTP/1.1 server.</p></div></div></div></body></html>