123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261(** Portable Lwt implementation of HTTP client and server, without depending on
a particular I/O implementation. The various [Make] functors must be
instantiated by an implementation that provides a concrete IO monad. *)(** The IO module is specialized for the [Lwt] monad. *)moduletypeIO=sigincludeCohttp.S.IOwithtype'at='aLwt.ttypeerrorvalcatch:(unit->'at)->('a,error)resultt(** [catch f] is [f () >|= Result.ok], unless [f] fails with an IO error, in
which case it returns the error. *)valpp_error:Format.formatter->error->unitend(** The [Net] module type defines how to connect to a remote node and close the
resulting channels to clean up. *)moduletypeNet=sigmoduleIO:IOtypeclienttypeendptypectx[@@derivingsexp_of](** Conduit context. Contains configuration of resolver, local source address,
TLS / SSL library, certificates, keys.
Depending on [ctx], the library is able to send HTTP requests unencrypted
or encrypted one with a secured protocol (such as TLS). Depending on how
conduit is configured, [ctx] might initiate a secured connection with TLS
(using [ocaml-tls]) or SSL (using [ocaml-ssl]), on [*:443] or on the
specified port by the user. If neitehr [ocaml-tls] or [ocaml-ssl] are
installed on the system, [cohttp]/[conduit] tries the usual ([*:80]) or
the specified port by the user in a non-secured way. *)valdefault_ctx:ctxLazy.tvalresolve:ctx:ctx->Uri.t->endpIO.t(** [resolve ~ctx uri] resolves [uri] into an endpoint description. This is
[Resolver_lwt.resolve_uri ~uri ctx.resolver]. *)valtunnel:string->IO.ic*IO.oc->clientvalconnect_uri:ctx:ctx->Uri.t->(IO.conn*IO.ic*IO.oc)IO.t(** [connect_uri ~ctx uri] starts a {i flow} on the given [uri]. The choice of
the protocol (with or without encryption) is done by the {i scheme} of the
given [uri]:
- If the scheme is [https], we will {b extend} [ctx] to be able to start a
TLS connection with a default TLS configuration (no authentication) on
the default or user-specified port.
- If the scheme is [http], we will {b extend} [ctx] to be able to start a
simple TCP/IP connection on the default or user-specified port.
These extensions have the highest priority ([Conduit] will try to initiate
a communication with them first). By {i extension}, we mean that the user
is able to fill its own [ctx] and we don't overlap resolution functions
from the given [ctx].
This is [resolve ~ctx uri >>= connect_endp ~ctx]. *)valconnect_endp:ctx:ctx->endp->(IO.conn*IO.ic*IO.oc)IO.t(** [connect_endp ~ctx endp] starts a {i flow} to the given [endp]. [endp]
describes address and protocol of the endpoint to connect to. *)valconnect_client:ctx:ctx->client->(IO.conn*IO.ic*IO.oc)IO.tvalclose_in:IO.ic->unitvalclose_out:IO.oc->unitvalclose:IO.ic->IO.oc->unitend(** This is compatible with [Mirage_time.S]. It may be satisfied by
mirage-time-unix [Time] or [Mirage_time]. *)moduletypeSleep=sigvalsleep_ns:int64->unitLwt.tendtypecall=?headers:Http.Header.t->?body:Body.t->?absolute_form:bool->Http.Method.t->Uri.t->(Cohttp.Response.t*Body.t)Lwt.t(** [call ?headers ?body method uri] Function type used to handle http requests
@return
[(response, response_body)] [response_body] 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 {!Body}
module can be used to consume [response_body]. Use {!Body.drain_body} if
you don't consume the body by other means.
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 [cohttp-lwt-unix]
{[
Cohttp_lwt_unix.Debug.activate_debug ();
Logs.set_level (Some Logs.Warning)
]}
@raise {!Connection.Retry}
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
[`Stream] [body] may have been consumed. *)(** The [Connection] module handles a single, possibly pipelined, http
connection. *)moduletypeConnection=sigmoduleNet:NetexceptionRetrytypetvalcreate:?finalise:(t->unitNet.IO.t)->?persistent:bool->?ctx:Net.ctx->Net.endp->t(** [create ?finalise ?persistent ?ctx endp] connects to [endp]. The
connection handle may be used immediately, although the connection may not
yet be established.
@param finalise
called when the connection is closed, but before still waiting requests
are failed.
@param persistent
if [false], a [Connection: close] header is sent and the connection
closed as soon as possible. If [true], it is assumed the remote end does
support pipelining and multiple requests may be sent even before
receiving any reply. By default we wait for the first response to decide
whether connection keep-alive and pipelining is supported. Chunked
encoding can only be used when pipelining is supported. Therefore better
avoid using chunked encoding on the very first request.
@param ctx See [Net.ctx]
@param endp The remote address, port and protocol to connect to. *)valcreate_tunnel:?finalise:(t->unitNet.IO.t)->?ctx:Net.ctx->t->string->tvalconnect:?finalise:(t->unitNet.IO.t)->?persistent:bool->?ctx:Net.ctx->Net.endp->tNet.IO.t(** Same as [create], but returns d promise which gets fulfilled when the
connection is established or rejected when connecting fails. *)valshutdown:t->unit(** Send {e EOF}. On {e TCP} connections send a {e FIN} packet. On {e TLS}
connections send a {e close notify}. No new requests can be sent
afterwards, but responses may still be received. *)valclose:t->unit(** Immediately close connection. All outstanding requests will fail, but
non-idempotent requests that already went out on the wire may have
produced side-effects. *)valis_closed:t->bool(** If [is_closed connection] is [false] the [connection] still accepts new
requests. *)vallength:t->int(** Number of unfulfilled requests. This includes requests already sent out
and requests still waitung to be sent. *)valnotify:t->unitNet.IO.t(** Request notification on change of [length] and on closing. *)valcall:t->call(** Queue a request. Please see {!type:requester}. *)end(** A [Connection_cache] handles http requests. It not necessarily caches
connections. *)moduletypeConnection_cache=sigtypetvalcall:t->call(** Process a request. Please see {!type:call}. *)end(** The [Client] module is a collection of convenience functions for
constructing and processing requests. *)moduletypeClient=sigtypectx(** @param ctx
If provided, no connection cache is used, but
{!val:Connection_cache.Make_no_cache.create} is used to resolve uri and
create a dedicated connection with [ctx].
In most cases you should use the more specific helper calls in the
interface rather than invoke this function directly. See {!head}, {!get}
and {!post} for some examples. *)includeCohttp.Generic.Client.Swithtype'aio='aLwt.tandtypebody=Body.tandtype'awith_context=?ctx:ctx->'avalset_cache:call->unit(** Provide a function used to process requests. Please see {!type:call}. The
provided function is only used when no [ctx] argument is passed to the
convenience functions below. *)valpost_form:?ctx:ctx->?headers:Http.Header.t->params:(string*stringlist)list->Uri.t->(Http.Response.t*Body.t)Lwt.tvalcallv:?ctx:ctx->Uri.t->(Http.Request.t*Body.t)Lwt_stream.t->(Http.Response.t*Body.t)Lwt_stream.tLwt.t(** @deprecated use {!module:Cohttp_lwt.Connection} instead. *)end(** The [Server] module implements a pipelined HTTP/1.1 server. *)moduletypeServer=sigmoduleIO:IOincludeCohttp.Generic.Server.Swithtypebody=Body.tandmoduleIO:=IOandtyperesponse=Http.Response.t*Body.tvalresolve_local_file:docroot:string->uri:Uri.t->string[@@deprecated"Please use Cohttp.Path.resolve_local_file. "](** Resolve a URI and a docroot into a concrete local filename. *)valrespond_error:?headers:Http.Header.t->?status:Http.Status.t->body:string->unit->(Http.Response.t*body)IO.tvalrespond_redirect:?headers:Http.Header.t->uri:Uri.t->unit->(Http.Response.t*body)IO.tvalrespond_need_auth:?headers:Http.Header.t->auth:Cohttp.Auth.challenge->unit->(Http.Response.t*body)IO.tvalrespond_not_found:?uri:Uri.t->unit->(Http.Response.t*body)IO.tend