Module Head.Response

A response's head, as a client reads it.

Two readers over one field grammar rather than one with flags, because a client and a server are owed different things by the same bytes: RFC 9112 §5.2 has a user agent join an obsolete fold that a server must refuse, and a response may end where its connection does.

type t = {
  1. version : version;
    (*

    HTTP/1.1 for any later HTTP/1 minor version, as for a request

    *)
  2. status : Status.t;
  3. reason : string;
    (*

    as sent, and nothing should act on it

    *)
  4. headers : (string * string) list;
    (*

    in the order sent, names as sent, values trimmed, a folded line joined onto the field before it

    *)
}
type error =
  1. | Closed
    (*

    the server went, or its connection failed, before a byte of a head -- which is what a kept connection the server gave up on looks like

    *)
  2. | Malformed of string
    (*

    anything else that is not a head, one cut short included, in words for a log

    *)

Why a response's head was not read: in the shape a request's is, since both are a connection's peer and what it sent.

val error_to_string : error -> string
val read : max:int -> Eio.Buf_read.t -> (t, error) Stdlib.result

The next head.

A status line is a version, a space, a code of three digits from 100 to 599, and the reason after a space; the space may be missing, since nothing turns on the reason. Another major version than HTTP/1 is malformed. An empty line before the status line is not skipped, as a server skips one before a request: to a client it is the last response ending somewhere its framing did not say. A field is what Field.parse reads, but for an obsolete fold, joined to the field before it as RFC 9112 §5.2 has a user agent join one; a bare CR and a head past max bytes are malformed, and a line may end in a bare LF.

A 1xx is a head of its own, with no body, and the final response follows it.

val keep_alive : t -> bool

Whether the server will keep the connection, on the same terms as Request.keep_alive. Whether the body leaves it where the next response begins is Framing's: a body delimited by the connection closing ends with it.