Module Webs.Req
HTTP requests.
Request bodies
type body
= unit -> (bytes * int * int) option
The type for request bodies.
Bodies are blocking functions pulled by services to yield byte chunks of data of the request body as
Some (bytes, first, len)
values. The bytes value must not be modified and is readable fromfirst
tofirst+len
until the next call to the function. The function returnsNone
at the end of stream.
val empty_body : body
empty_body
is an empty body.
val body_to_string : body -> string
body_to_string b
accumulates the body to a string.
HTTP Requests
val v : ?env:Env.t -> ?version:Http.version -> ?body_length:int option -> ?body:body -> ?headers:Http.headers -> Http.meth -> string -> t
v meth request_target
is an HTTP request with methodmeth
, request targetrequest_target
,headers
(defaults toHttp.H.empty
),body
(defaults toempty_body
),body_length
(defaults toNone
orSome 0
if body isempty_body
) and version (defaults to (1,1)).
val version : t -> Http.version
version r
isr
's HTTP version.
val meth : t -> Http.meth
meth r
isr
's HTTP method.
val request_target : t -> string
request_target
isr
's request target. This should be the raw request, still percent encoded. Note that you usually rather want to use the conveniencepath
andquery
which are derived from this value.
val path : t -> Http.path
path r
is the absolute path ofrequest_target
as a list of path segments or the empty list if there is none. Note that the path segements are percent decoded, this means they may have stray '/' embedded.TODO say something about the other request target cases in particular should we map "*" on
or
"/"
? Also should we undot and compress by default, seems like a good safer default, people who want the gory details can userequest_target
. However that's likely not a good idea since this people make people 200 these paths.
val query : t -> string option
query r
is the query (without the'?'
) ofrequest_target
. Note that query string may be the empty string which is different fromNone
(no'?'
in the request target).
val headers : t -> Http.headers
headers r
isr
's HTTP headers. Includes at least theHttp.H.host
header.
val body_length : t -> int option
body_length r
isr
's request body length (if known).
val with_headers : Http.headers -> t -> t
with_headers hs r
isr
with headershs
.
val with_body : body_length:int option -> body -> t -> t
with_body blen b r
isr
with body lengthblen
and bodyb
.
val pp : Stdlib.Format.formatter -> t -> unit
pp ppf req
prints and unspecified representation ofreq
onppf
but guarantees not to consume the Request bodies.