Module Webs.HTTP.H

module H: sig .. end
Headers.

Consult the header name constants.

FIXME. This is not the right way to do this. Internally we are using multi by default, but in fact we should not as we may not know if a field is multi or not (because of extensions). The decoder should simply combine multi into single by using ',' *except* for Set-Cookie, we then leave it to the user to decompose a multi value using Webs.HTTP.H.decode_multi_value on values that make sense to her to treat that way (which may not be standard). However we then need to provide special functions for Set-Cookie.



Header names


type name 
The type for lowercased HTTP header field-names.
val name : string -> name
name s is a header name from s. See also the header name constants.
Raises Invalid_argument if s is not a field-name Use Webs.HTTP.H.decode_name if you need to handle failures.
val name_equal : name -> name -> bool
name_equal n n' is true iff n and n' are equal.
val decode_name : string -> name option
decode_name s decodes and lowercases a field-name from s.
val encode_name : name -> string
encode_name n encodes a field-name for n.
val pp_name : Format.formatter -> name -> unit
pp_name ppf n prints an unspecified representation of n on ppf.

Header maps


val empty : Webs.HTTP.headers
empty is the empty header map.
val is_empty : Webs.HTTP.headers -> bool
is_empty hs is true iff hs is the empty header map.
val is_def : name -> Webs.HTTP.headers -> bool
is_def n hs is true iff n is bound in hs.
val undef : name -> Webs.HTTP.headers -> Webs.HTTP.headers
undef n hs is hs without a binding for n.

Single-valued header definition


val def : name -> string -> Webs.HTTP.headers -> Webs.HTTP.headers
def n v hs is hs with n bound to v.
val redef : name ->
(string option -> string option) -> Webs.HTTP.headers -> Webs.HTTP.headers
redef n f hs is:
val def_if_undef : name -> string -> Webs.HTTP.headers -> Webs.HTTP.headers
def_if_undef n v hs is:
val find : name -> Webs.HTTP.headers -> string option
find n hs is the value of header n in hs (if defined). If n is multi-valued and defined, the result of Webs.HTTP.H.encode_multi_value on the list of values is returned.

Warning. Do not use this function with Webs.HTTP.H.set_cookie.

val get : name -> Webs.HTTP.headers -> string
get n hs is like Webs.HTTP.H.find but
Raises Invalid_argument if n is undefined in hs.

Multi-valued header definition


val def_multi : name -> string list -> Webs.HTTP.headers -> Webs.HTTP.headers
def_multi n vs hs is hs with n bound to the multi-value vs.
Raises Invalid_argument if vs is [].
val redef_multi : name ->
(string list option -> string list option) ->
Webs.HTTP.headers -> Webs.HTTP.headers
redef n f hs is:
Raises Invalid_argument if f returns Some [].
val def_if_undef_multi : name -> string list -> Webs.HTTP.headers -> Webs.HTTP.headers
def_if_undef_multi n vs hs is:
Raises Invalid_argument if vs is [].
val find_multi : name -> Webs.HTTP.headers -> string list option
find_multi n hs is the value of header n in hs as a multi-valued header (if defined). If n is not multi-valued a singleton list is returned with the header value. Returned lists are never empty.
val get_multi : name -> Webs.HTTP.headers -> string list
get n hs is like Webs.HTTP.H.find_multi but
Raises Invalid_argument if n is undefined in hs.

Map folding, predicates and conversion

The following functions only work on the multi valued representation as automatic Webs.HTTP.H.encode_multi_value is not feasable because of Webs.HTTP.H.set_cookie.

val fold : (name -> string list -> 'a -> 'a) ->
Webs.HTTP.headers -> 'a -> 'a
fold f m acc folds f over the bindings of hs starting with acc.
val iter : (name -> string list -> unit) -> Webs.HTTP.headers -> unit
iter f hs iters f over the bindings of hs.
val for_all : (name -> string list -> bool) -> Webs.HTTP.headers -> bool
for_all p hs is true iff all binding in hs satisfy p.
val exists : (name -> string list -> bool) -> Webs.HTTP.headers -> bool
exists p hs is true iff there is a binding in hs that satisfies p.
val keep_if : (name -> string list -> bool) ->
Webs.HTTP.headers -> Webs.HTTP.headers
keep_if p hs is the bindings of hs that satisfiy p.
val partition : (name -> string list -> bool) ->
Webs.HTTP.headers -> Webs.HTTP.headers * Webs.HTTP.headers
partition p hs is (t, f) where t are the bindings of hs that do satisfy p and f those that do not satisfy p.
val bindings : Webs.HTTP.headers -> (name * string list) list
bindings hs is hs's list of bindings.
val cardinal : Webs.HTTP.headers -> int
cardinal hs is hs's number of bindings in hs.

Header values


val decode_multi_value : string -> string list
decode_multi_value s splits the string s at ',' characters and trims the resulting strings from optional whitespace. Note that by definition the result is never the empty list, the function returns [""] on "".
val encode_multi_value : string list -> string
encode_multi_value vs is String.concat "," vs but
Raises Invalid_argument if vs is [].

Header name values


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
val cookie : name
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
val set_cookie : name
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