Module Head.Request

A request's head, as a server reads it.

type form =
  1. | Origin
    (*

    /path?query, the ordinary one

    *)
  2. | Absolute
    (*

    http://host/path, as a proxy is sent it

    *)
  3. | Authority
    (*

    host:port, CONNECT's

    *)
  4. | Asterisk
    (*

    *, a server-wide OPTIONS

    *)

The request-target's form (RFC 9112 §3.2).

type t = {
  1. meth : Meth.t;
  2. target : string;
    (*

    the request-target as it arrived

    *)
  3. form : form;
  4. version : version;
    (*

    HTTP/1.1 for any later HTTP/1 minor version, which is answered as the highest this server speaks

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

    in the order sent, names as sent, values trimmed

    *)
  6. host : string option;
    (*

    the host the request is for, as it was sent: an absolute-form or authority-form target's authority, otherwise the Host field -- None when neither names one

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

The next head. Empty lines before it are skipped, as RFC 9112 asks. A request line is a method token, a target of visible ASCII and a version, each one space apart: another major version than HTTP/1 is 505, and a request line past max bytes 414. The target's form must be one its method may use, and an absolute one's authority a host with no userinfo. A field is what Field.parse reads; a bare CR and a field section past max bytes -- 431 -- are refused, and a line may end in a bare LF, which RFC 9112 lets a recipient accept.

An HTTP/1.1 request needs exactly one Host, and no request may carry two or one that is not a host (400, RFC 9112 §3.2) -- an absolute-form target included, whose authority is then the host all the same. A path or an asterisk names no host of its own, so beside one an empty Host is 400 too (RFC 9110 §4.2.1). A host is RFC 3986's: a name, or in brackets an IPv6 address or an IPvFuture, and never any other run of characters there; CONNECT's target is a host and a port, both there.

val keep_alive : t -> bool

Whether the client asked to keep the connection: HTTP/1.1 unless Connection: close, and HTTP/1.0 only with Connection: keep-alive -- and never after an HTTP/1.0 request carrying Transfer-Encoding, which HTTP/1.0 does not have, so whoever framed it cannot be trusted to have ended it where it ends (RFC 9112 §6.1).