Module Httpaf.Headers
Header Fields
Each header field consists of a case-insensitive field name and a field value. The order in which header fields with differing field names are received is not significant. However, it is good practice to send header fields that contain control data first so that implementations can decide when not to handle a message as early as possible.
A sender MUST NOT generate multiple header fields with the same field name in a message unless either the entire field value for that header field is defined as a comma-separated list or the header field is a well-known exception, e.g., Set-Cookie.
A recipient MAY combine multiple header fields with the same field name into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field value to the combined field value in order, separated by a comma. The order in which header fields with the same field name are received is therefore significant to the interpretation of the combined field value; a proxy MUST NOT change the order of these field values when forwarding a message.
Note. Unless otherwise specified, all operations preserve header field order and all reference to equality on names is assumed to be case-insensitive.
See RFC7230§3.2 for more details.
Constructor
val empty : temptyis the empty collection of header fields.
val of_list : (name * value) list -> tof_list associs a collection of header fields defined by the association listassoc.of_listassumes the order of header fields inassocis the intended transmission order. The following equations should hold:to_list (of_list lst) = lstget (of_list [("k", "v1"); ("k", "v2")]) "k" = Some "v2".
val of_rev_list : (name * value) list -> tof_list associs a collection of header fields defined by the association listassoc.of_listassumes the order of header fields inassocis the reverse of the intended trasmission order. The following equations should hold:to_list (of_rev_list lst) = List.rev lstget (of_rev_list [("k", "v1"); ("k", "v2")]) "k" = Some "v1".
val to_list : t -> (name * value) listto_list tis the association list of header fields contained intin transmission order.
val to_rev_list : t -> (name * value) listto_rev_list tis the association list of header fields contained intin reverse transmission order.
val add : t -> name -> value -> tadd t name valueis a collection of header fields that is the same astexcept with(name, value)added at the end of the trasmission order. The following equations should hold:get (add t name value) name = Some value
val add_unless_exists : t -> name -> value -> tadd_unless_exists t name valueis a collection of header fields that is the same astiftalready incluesname, and otherwise is equivalent toadd t name value.
val add_list : t -> (name * value) list -> tadd_list t associs a collection of header fields that is the same astexcept with all the header fields inassocadded to the end of the transmission order, in reverse order.
val add_multi : t -> (name * value list) list -> tadd_multi t associs the same asadd_list t (List.concat_map assoc ~f:(fun (name, values) -> List.map values ~f:(fun value -> (name, value))))but is implemented more efficiently. For example,
add_multi t ["name1", ["x", "y"]; "name2", ["p", "q"]] = add_list ["name1", "x"; "name1", "y"; "name2", "p"; "name2", "q"]
val remove : t -> name -> tremove t nameis a collection of header fields that contains all the header fields oftexcept those that have a header-field name that are equal toname. Iftcontains multiple header fields whose name isname, they will all be removed.
val replace : t -> name -> value -> treplace t name valueis a collection of header fields that is the same astexcept with all header fields with a name equal tonameremoved and replaced with a single header field whose name isnameand whose value isvalue. This new header field will appear in the transmission order where the first occurrence of a header field with a name matchingnamewas found.If no header field with a name equal to
nameis present int, then the result is simplyt, unchanged.
Destructors
val mem : t -> name -> boolmem t nameis true ifftincludes a header field with a name that is equal toname.
val get : t -> name -> value optionget t namereturns the last header fromtwith namename, orNoneif no such header is present.