Module Http.H

HTTP headers and values.

Headers

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 digits_of_string : string -> (int, string) Stdlib.result

digits_of_string s is the non-empty sequence of decimal digits s as a non-negative integer.

val digits_to_string : int -> string

digits_to_string n is the non-negative integer n as a sequence of decimal digits.

raises Invalid_argument

if n is negative.

val is_token : string -> bool

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

Standard header names

val accept : name

accept

val accept_charset : name

accept-charset

val accept_encoding : name

accept-encoding

val accept_language : name

accept-language

val accept_ranges : name

accept-ranges

val age : name

age

val allow : name

allow

val authorization : name

authorization

val cache_control : name

cache-control

val connection : name

connection

val content_encoding : name

content-encoding

val content_language : name

content-language

val content_length : name

content-length

val content_location : name

content-location

val content_range : name

content-range

val content_type : name

content-type

cookie

val date : name

date

val etag : name

etag

val expect : name

expect

val expires : name

expires

val from : name

from

val host : name

host

val if_match : name

if-match

val if_modified_since : name

if-modified-since

val if_none_match : name

if-none-match

val if_range : name

if-range

val if_unmodified_since : name

if-unmodified-since

val last_modified : name

last-modified

val location : name

location

val max_forwards : name

max-forwards

val pragma : name

pragma

val proxy_authenticate : name

proxy-authenticate

val proxy_authorization : name

proxy-authorization

val range : name

range

val referer : name

referer

val retry_after : name

retry-after

val server : name

server

set-cookie

val te : name

te

val trailer : name

trailer

val transfer_encoding : name

transfer-encoding

val upgrade : name

upgrade

val user_agent : name

user-agent

val vary : name

vary

val via : name

via

val warning : name

warning

val www_authenticate : name

www-authenticate