Module Webs_http11

HTTP/1.1 (de)serialization

Versions

val decode_version : string -> (Webs.Http.Version.t, string) Stdlib.result

decode_version s decodes a version in HTTP/1.1 syntax from s. Single digit versions are also parsed, some serializations (e.g. the curl tool) do that.

val encode_version : Webs.Http.Version.t -> string

http11_encode v encodes the version v in HTTP/1.1 syntax. Assumes correct integer ranges.

Headers

val decode_headers : bytes -> crlfs:int list -> Webs.Http.Headers.t

decode_headers b crlfs decodes the headers. b has the header section with the start line (either request or status line) or finished by the first crlfs.

Requests

val decode_request_line : bytes -> first:int -> crlf:int -> Webs.Http.Method.t * string * Webs.Http.Version.t

decode_request_line b ~first ~crlf decodes a request line that starts at first and whose ending CRLF starts at crlf. Raises Failure on errors.

val encode_request_head : Webs.Http.Request.t -> string

encode_request_head request is the message head of request: the start line, the crlf-terminated headers and the final crlf.

This calls Webs.Http.Headers.for_connector to determine the headers and the value of Webs.Http.Request.version is ignored.

val encode_request : Webs.Http.Request.t -> (string, string) Stdlib.result

encode_request ~include_body request encodes request to an HTTP/1.1 request with encode_request_head and appends the body.

This errors on Webs.Http.Body.content.Custom bodies.

val write_request_head : Bytesrw.Bytes.Writer.t -> Webs.Http.Request.t -> unit

write_request_head w request writes the result of encode_request_head on w.

val write_request : eod:bool -> Bytesrw.Bytes.Writer.t -> Webs.Http.Request.t -> (unit, string) Stdlib.result

write_request ~eod w writes the result of encode_request on w (but streams the bodies if possible).

Responses

val decode_status_line : bytes -> first:int -> crlf:int -> Webs.Http.Version.t * Webs.Http.Status.t * string

decode_status_line b ~first ~crlf decodes a status line that starts at first and whose ending CRLF starts at crlf. Raises Failure on errors.

val decode_response : bytes -> first:int -> Webs.Http.Response.t

decode_response b ~first body decodes an HTTP/1.1 full response from b starting at first. The result satisfies client responses. Raises Failure on errors.

val read_response : ?head_buffer:bytes -> Bytesrw.Bytes.Reader.t -> (Webs.Http.Response.t, string) Stdlib.result

read_response r reads a response using head_buffer to store the response head, defaults to a fresh buffer of size Http.Connector.Default.max_request_headers_byte_size.

val encode_response_head : Webs.Http.Status.t -> reason:string -> Webs.Http.Headers.t -> string

encode_http11_response_head is the HTTP/1.1 head for a response with the given parameters. This has the final double CRLF.

val encode_response : include_body:bool -> Webs.Http.Response.t -> (string, string) Stdlib.result

encode_http11 ~include_body response encodes response to an HTTP/1.1 response. If include_body is true the body is consumed and included in the result. If false the body is left untouched and the encoding stops after the header final double CRLF.