Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file s.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189(** 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. *)moduletypeIO=Cohttp.S.IOwithtype'at='aLwt.t(** The IO module is specialized for the [Lwt] monad. *)(** The [Net] module type defines how to connect to a remote node
and close the resulting channels to clean up. *)moduletypeNet=sigmoduleIO:IOtypectx[@@derivingsexp_of]valdefault_ctx:ctxvalconnect_uri:ctx:ctx->Uri.t->(IO.conn*IO.ic*IO.oc)Lwt.tvalclose_in:IO.ic->unitvalclose_out:IO.oc->unitvalclose:IO.ic->IO.oc->unitend(** The [Client] module implements non-pipelined single HTTP client
calls. Each call will open a separate {! Net } connection. For
best results, the {! Body } that is returned should be
consumed in order to close the file descriptor in a timely
fashion. It will still be finalized by a GC hook if it is not used
up, but this can take some additional time to happen. *)moduletypeClient=sigtypectx[@@derivingsexp_of]valdefault_ctx:ctx(** [call ?ctx ?headers ?body ?chunked meth uri] will resolve the
[uri] to a concrete network endpoint using the resolver initialized
in [ctx]. It will then issue an HTTP request with method [meth],
adding request headers from [headers] if present. If a [body]
is specified then that will be included with the request, using
chunked encoding if [chunked] is true. The default is to disable
chunked encoding for HTTP request bodies for compatibility reasons.
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. *)valcall:?ctx:ctx->?headers:Cohttp.Header.t->?body:Body.t->?chunked:bool->Cohttp.Code.meth->Uri.t->(Cohttp.Response.t*Body.t)Lwt.tvalhead:?ctx:ctx->?headers:Cohttp.Header.t->Uri.t->Cohttp.Response.tLwt.tvalget:?ctx:ctx->?headers:Cohttp.Header.t->Uri.t->(Cohttp.Response.t*Body.t)Lwt.tvaldelete:?ctx:ctx->?body:Body.t->?chunked:bool->?headers:Cohttp.Header.t->Uri.t->(Cohttp.Response.t*Body.t)Lwt.tvalpost:?ctx:ctx->?body:Body.t->?chunked:bool->?headers:Cohttp.Header.t->Uri.t->(Cohttp.Response.t*Body.t)Lwt.tvalput:?ctx:ctx->?body:Body.t->?chunked:bool->?headers:Cohttp.Header.t->Uri.t->(Cohttp.Response.t*Body.t)Lwt.tvalpatch:?ctx:ctx->?body:Body.t->?chunked:bool->?headers:Cohttp.Header.t->Uri.t->(Cohttp.Response.t*Body.t)Lwt.tvalpost_form:?ctx:ctx->?headers:Cohttp.Header.t->params:(string*stringlist)list->Uri.t->(Cohttp.Response.t*Body.t)Lwt.tvalcallv:?ctx:ctx->Uri.t->(Cohttp.Request.t*Body.t)Lwt_stream.t->(Cohttp.Response.t*Body.t)Lwt_stream.tLwt.tend(** The [Server] module implements a pipelined HTTP/1.1 server. *)moduletypeServer=sigmoduleIO:IOtypeconn=IO.conn*Cohttp.Connection.t(** A request handler can respond in two ways:
- Using [`Response], with a {!Response.t} and a {!Body.t}.
- Using [`Expert], with a {!Response.t} and an IO function that is
expected to write the response body. The IO function has access to the
underlying {!IO.ic} and {!IO.oc}, 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
{!unit Lwt.t} is resolved. The connection can be closed by closing the
{!IO.ic}. *)typeresponse_action=[`ExpertofCohttp.Response.t*(IO.ic->IO.oc->unitLwt.t)|`ResponseofCohttp.Response.t*Body.t]typetvalmake_response_action:?conn_closed:(conn->unit)->callback:(conn->Cohttp.Request.t->Body.t->response_actionLwt.t)->unit->tvalmake_expert:?conn_closed:(conn->unit)->callback:(conn->Cohttp.Request.t->Body.t->(Cohttp.Response.t*(IO.ic->IO.oc->unitLwt.t))Lwt.t)->unit->tvalmake:?conn_closed:(conn->unit)->callback:(conn->Cohttp.Request.t->Body.t->(Cohttp.Response.t*Body.t)Lwt.t)->unit->t(** Resolve a URI and a docroot into a concrete local filename. *)valresolve_local_file:docroot:string->uri:Uri.t->string(** [respond ?headers ?flush ~status ~body] will respond to an HTTP
request with the given [status] code and response [body]. If
[flush] is true, then every response chunk will be flushed to
the network rather than being buffered. [flush] is true by default.
The transfer encoding will be detected from the [body] value and
set to chunked encoding if it cannot be determined immediately.
You can override the encoding by supplying an appropriate [Content-length]
or [Transfer-encoding] in the [headers] parameter. *)valrespond:?headers:Cohttp.Header.t->?flush:bool->status:Cohttp.Code.status_code->body:Body.t->unit->(Cohttp.Response.t*Body.t)Lwt.tvalrespond_string:?flush:bool->?headers:Cohttp.Header.t->status:Cohttp.Code.status_code->body:string->unit->(Cohttp.Response.t*Body.t)Lwt.tvalrespond_error:?headers:Cohttp.Header.t->?status:Cohttp.Code.status_code->body:string->unit->(Cohttp.Response.t*Body.t)Lwt.tvalrespond_redirect:?headers:Cohttp.Header.t->uri:Uri.t->unit->(Cohttp.Response.t*Body.t)Lwt.tvalrespond_need_auth:?headers:Cohttp.Header.t->auth:Cohttp.Auth.challenge->unit->(Cohttp.Response.t*Body.t)Lwt.tvalrespond_not_found:?uri:Uri.t->unit->(Cohttp.Response.t*Body.t)Lwt.tvalcallback:t->IO.conn->IO.ic->IO.oc->unitLwt.tend