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 from first to first+len until the next call to the function. The function returns None 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

type t

The type for 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 method meth, request target request_target, headers (defaults to Http.H.empty), body (defaults to empty_body), body_length (defaults to None or Some 0 if body is empty_body) and version (defaults to (1,1)).

val version : t -> Http.version

version r is r's HTTP version.

val meth : t -> Http.meth

meth r is r's HTTP method.

val request_target : t -> string

request_target is r's request target. This should be the raw request, still percent encoded. Note that you usually rather want to use the convenience path and query which are derived from this value.

val path : t -> Http.path

path r is the absolute path of request_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 use request_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 '?') of request_target. Note that query string may be the empty string which is different from None (no '?' in the request target).

val headers : t -> Http.headers

headers r is r's HTTP headers. Includes at least the header.

val body_length : t -> int option

body_length r is r's request body length (if known).

val body : t -> body

body r is r's body.

val with_headers : Http.headers -> t -> t

with_headers hs r is r with headers hs.

val with_body : body_length:int option -> body -> t -> t

with_body blen b r is r with body length blen and body b.

val with_path : Http.path -> t -> t

with_path p r is r with path p.

val env : t -> Env.t

env r is r's environment. TODO consider removing.

val with_env : Env.t -> t -> t

with_env e r is r with environment e. TODO consider removing.

val pp : Stdlib.Format.formatter -> t -> unit

pp ppf req prints and unspecified representation of req on ppf but guarantees not to consume the Request bodies.