Tiny_httpd_core.RequestRequests
Requests are sent by a client, e.g. a web browser or cURL. From the point of view of the server, they're inputs.
type 'body t = private {meth : Meth.t;HTTP method for this request.
*)host : string;client_addr : Unix.sockaddr;Client address. Available since 0.14.
*)headers : Headers.t;List of headers.
*)mutable meta : Hmap.t;Metadata.
*)http_version : int * int;HTTP version. This should be either 1, 0 or 1, 1.
path : string;Full path of the requested URL.
*)path_components : string list;Components of the path of the requested URL.
*)query : (string * string) list;Query part of the requested URL.
*)body : 'body;Body of the request.
*)start_time : float;Obtained via get_time_s in create
}A request with method, path, host, headers, and a body, sent by a client.
The body is polymorphic because the request goes through several transformations. First it has no body, as only the request and headers are read; then it has a stream body; then the body might be entirely read as a string via read_body_full.
val pp_with :
?mask_header:(string -> bool) ->
?headers_to_mask:string list ->
?show_query:bool ->
?pp_body:(Stdlib.Format.formatter -> 'body -> unit) ->
unit ->
Stdlib.Format.formatter ->
'body t ->
unitPretty print the request. The exact format of this printing is not specified.
val pp : Stdlib.Format.formatter -> string t -> unitPretty print the request and its body. The exact format of this printing is not specified.
val pp_ : Stdlib.Format.formatter -> _ t -> unitPretty print the request without its body. The exact format of this printing is not specified.
val get_header : ?f:(string -> string) -> _ t -> string -> string optionget_header req h looks up header h in req. It returns None if the header is not present. This is case insensitive and should be used rather than looking up h verbatim in headers.
val get_header_int : _ t -> string -> int optionSame as get_header but also performs a string to integer conversion.
set_header k v req sets k: v in the request req's headers.
Modify headers using the given function.
val host : _ t -> stringHost field of the request. It also appears in the headers.
val client_addr : _ t -> Unix.sockaddrClient address of the request.
val path : _ t -> stringRequest path.
val body : 'b t -> 'bRequest body, possibly empty.
val start_time : _ t -> floattime stamp (from Unix.gettimeofday) after parsing the first line of the request
val limit_body_size :
max_size:int ->
bytes:bytes ->
IO.Input.t t ->
IO.Input.t tLimit the body size to max_size bytes, or return a 413 error.
val read_body_full : ?bytes:bytes -> ?buf_size:int -> IO.Input.t t -> string tRead the whole body into a string. Potentially blocking.