Module Http.Headers

HTTP headers and values.


val name : string -> name

name n is Http.Header_name.v.

type t = headers

See headers.

val empty : headers

empty has no header definition.

val is_empty : headers -> bool

is_empty hs is true iff hs is has no definition.

val mem : name -> headers -> bool

mem n hs is true iff n is defined in hs.

val find : ?lowervalue:bool -> name -> headers -> string option

find n hs is the value of n in hs (if any). If lowervalue is true (defaults to false) the US-ASCII uppercase letter are mapped on lowercase.

If n is a multi-valued header use decode_multi_value on the result. If n is set_cookie you must use values_of_set_cookie_value.

val get : ?lowervalue:bool -> name -> headers -> string

get n hs is like find but raises Invalid_argument if n is not defined in hs.

val def : name -> string -> headers -> headers

def n v hs is hs with n defined to v.

val def_if_some : name -> string option -> headers -> headers

def_some n o hs is hs with n defined to v if o is Some v and hs otherwise.

val def_if_undef : name -> string -> headers -> headers

def_if_undef n v hs is hs with n defined to v if n is not defined in hs.

val add : name -> string -> headers -> headers

add n v hs appends v to the multi-valued header n in hs.

add_set_cookie c hs adds a set_cookie header with value c. This appends to set_cookie, see t.

val undef : name -> headers -> headers

undef n hs is hs with n undefined.

val override : headers -> by:headers -> headers

override hs ~by are the headers of both hs and by with those of by taking over.

val fold : (name -> string -> 'a -> 'a) -> headers -> 'a -> 'a

fold f m acc folds f over the bindings of hs starting with acc.

val pp : Stdlib.Format.formatter -> headers -> unit

pp ppf hs prints an unspecified representation of hs on ppf.

Header specific lookups

val request_body_length : headers -> ([ `Length of int | `Chunked ], string) Stdlib.result

request_body_length hs determines the message body length of a request (the rules for responses is a bit different) as per specification, by looking at the content_type and transfer_encoding in hs.

Header values

values_of_set_cookie_value v decodes v as stored in by set_set_cookie in the t type to a list of cookies.

val values_of_string : ?sep:char -> string -> string list

values_of_string s splits the string s at ',' (or sep if specified) characters and trims the resulting strings from optional whitespace, and lowercases the result if lowercase is true.

Note that by definition the result is never the empty list, the function returns [""] on "".

val values_to_string : ?sep:char -> string list -> string

values_to_string vs is String.concat "," vs but raise Invalid_argument if vs is []. TODO why ?

val is_token : string -> bool

is_token s is true iff s in an HTTP a token.