Module Http.H

HTTP headers and values.


val name : string -> name

name n is Http.Header_name.v.

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 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.

Standard header names

val accept : name
val accept_charset : name
val accept_encoding : name
val accept_language : name
val accept_ranges : name
val age : name
val allow : name
val authorization : name
val cache_control : name
val connection : name
val content_encoding : name
val content_language : name
val content_length : name
val content_location : name
val content_range : name
val content_type : name
val date : name
val etag : name
val expect : name
val expires : name
val from : name
val host : name
val if_match : name
val if_modified_since : name
val if_none_match : name
val if_range : name
val if_unmodified_since : name
val last_modified : name
val location : name
val max_forwards : name
val pragma : name
val proxy_authenticate : name
val proxy_authorization : name
val range : name
val referer : name
val retry_after : name
val server : name
val te : name
val trailer : name
val transfer_encoding : name
val upgrade : name
val user_agent : name
val vary : name
val via : name
val warning : name
val www_authenticate : name