Module Webs_http11.Response

Response codec.

val decode_status_line : bytes -> first:int -> last: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 last+1. Raises Failure on errors.

TODO Do not expose this.

Decoding

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

read r reads an HTTP/1.1 response from r. The body of the response is an Webs.Http.Body.content.Bytes_reader on r.

The function errors if the message head cannot fit in head_buffer or if a decoding error occurs.

Encoding

val encode_head : Webs.Http.Response.t -> string

encode_head response is the HTTP/1.1 message head of reponse: the status line, the crlf-terminated headers and the final crlf. The written headers go through Webs.Http.Headers.for_connector with the body of response.

val encode : Webs.Http.Response.t -> string

encode response encodes response to an HTTP/1.1 response with encode_head followed by the response body.

Raises Invalid_argument on Webs.Http.Body.content.Custom bodies.

val write_head : Bytesrw.Bytes.Writer.t -> Webs.Http.Response.t -> unit

write_head w response writes the encode_head of response on w.

val write : eod:bool -> Bytesrw.Bytes.Writer.t -> Webs.Http.Response.t -> unit

write ~eod w response writes response as an HTTP/1.1 response on w with write_head, followed by the response body and a final Bytes.Slice.eod iff eod is true.

Raises Invalid_argument on Webs.Http.Body.content.Custom bodies.