module Header:sig
..end
get_*
functions generally raise Not_found
when the queried header
is not present. If the syntax of the field is a comma-separated list of
multiple values, the get_*
functions generally merge all headers of
the same type. The order is preserved in this case. The list []
means
that the header exists, but only with empty value. For example,
Accept: text/html
Accept: text/plain
would be returned as ["text/html",[],[]; "text/plain", [],[]]
by get_accept
. The header
Accept:
would be returned as []
.
The set_*
functions generally produce only a single header with comma-
separated values. Existing header are overwritten/removed.
To remove a header, simply use the delete_field
method of http_header
.
Error behaviour: The get_*
functions raise Bad_header_field
when they cannot parse a header field. The set_*
functions
raise Invalid_argument
when an invalid value is passed to them
(only very few functions do that). The argument of both
exceptions is the function name.
typeparam_value =
[ `Q of string | `V of string ]
`Q
) or as already decoded values (`V
)typeauth_challenge =
string * (string * param_value) list
(mechanism_name, params)
. The headers
www-authenticate
and proxy-authenticate
use this.
See RFC 7235 for general information.
typeauth_credentials =
string * (string * param_value) list
(mechanism_name, params)
.
The headers authorize
and proxy-authorize
use this.
See RFC 7235 for general information.
val parse_quoted_parameters : string -> (string * string) list
val get_accept : #Nethttp.http_header_ro ->
(string * (string * string) list * (string * string) list) list
Accept
header as list of triples (media_range,
media_range_params, accept_params)
. If there are
accept_params
, the first such parameter is always "q"
.
All present Accept
headers are merged. The function returns
[]
when there is at least one Accept
header, but none of
the headers has a non-empty value. The function raises
Not_found
if there no such headers at all (which should be
interpreted as ["*/*",[],[] ]
).
val best_media_type : #Nethttp.http_header_ro -> string list -> string * (string * string) list
val set_accept : #Nethttp.http_header ->
(string * (string * string) list * (string * string) list) list -> unit
Accept
headerval get_accept_charset : #Nethttp.http_header_ro -> (string * (string * string) list) list
Accept-charset
header as list of pairs (charset,params)
.
The only mentioned parameter in RFC 2616 is "q"
.
All present Accept-charset
headers are merged. The function
raises Not_found
when there is no Accept-charset
header
(which should be interpreted as ["*",[]]
).
val best_charset : #Nethttp.http_header_ro -> string list -> string
This function already implements the special handling of ISO-8859-1
mentioned in RFC 2616.
val set_accept_charset : #Nethttp.http_header -> (string * (string * string) list) list -> unit
Accept-charset
headerval get_accept_encoding : #Nethttp.http_header_ro -> (string * (string * string) list) list
Accept-encoding
header as list of pairs (coding,params)
.
The only mentioned parameter in RFC 2616 is "q"
. The RFC describes
compatibility problems with the "q" parameter.
All present Accept-encoding
headers are merged. The function
raises Not_found
when there is no Accept-encoding
header
(which should be interpreted as ["identity",[]]
). The
return value []
must be interpreted as ["identity",[]]
.
val best_encoding : #Nethttp.http_header_ro -> string list -> string
val set_accept_encoding : #Nethttp.http_header -> (string * (string * string) list) list -> unit
Accept-encoding
headerval get_accept_language : #Nethttp.http_header_ro -> (string * (string * string) list) list
Accept-language
header as list of pairs
(lang_range,params)
. The only mentioned parameter in RFC
2616 is "q"
.
All present Accept-language
headers are merged. The function
raises Not_found
when there is no Accept-language
header
(which should be interpreted as ["*",[]]
).
val set_accept_language : #Nethttp.http_header -> (string * (string * string) list) list -> unit
Accept-language
headerval get_accept_ranges : #Nethttp.http_header_ro -> string list
Accept-ranges
header as list of tokens.
All present Accept-ranges
headers are merged. The function
raises Not_found
when there is no Accept-ranges
header. The RFC leaves it open how this is to be interpreted
in general.
val set_accept_ranges : #Nethttp.http_header -> string list -> unit
Accept-ranges
headerval get_age : #Nethttp.http_header_ro -> float
Age
header as numberval set_age : #Nethttp.http_header -> float -> unit
Age
headerval get_allow : #Nethttp.http_header_ro -> string list
Allow
header as list of tokens.
All present Allow
headers are merged. The function raises Not_found
when there is no Allow
header. The RFC leaves it open how this is
to be interpreted in general.
val set_allow : #Nethttp.http_header -> string list -> unit
Allow
header#Nethttp.http_header_ro -> auth_credentials
: Authorization
header as pair (auth_scheme,auth_params)
,
or raises Not_found
if not present.
The "Basic" authentication scheme is represented specially as
("basic", [ "credentials", creds ])
where creds
are the
Base64-encoded credentials.
At present, parameters are always decoded (`V
).
#Nethttp.http_header -> auth_credentials -> unit
: Authorization
header.
The "Basic" authentication scheme is represented as explained for
get_authorization
.val get_cache_control : #Nethttp.http_header_ro -> Nethttp.cache_control_token list
Cache-control
header as list of tokens.
All present Cache-control
headers are merged. The function
raises Not_found
when there is no Cache-control
header.
val set_cache_control : #Nethttp.http_header -> Nethttp.cache_control_token list -> unit
Cache-control
headerval get_connection : #Nethttp.http_header_ro -> string list
Connection
header as list of tokens.
All present Connection
headers are merged. The function
raises Not_found
when there is no Connection
header.
The Connection header must be ignored when received from a
HTTP/1.0 client.
val set_connection : #Nethttp.http_header -> string list -> unit
Connection
headerval get_content_encoding : #Nethttp.http_header_ro -> string list
Content-encoding
header as list of tokens.
All present Content-encoding
headers are merged.
Raises Not_found
when there is no Content-encoding
header.
val set_content_encoding : #Nethttp.http_header -> string list -> unit
Content-encoding
headerval get_content_language : #Nethttp.http_header_ro -> string list
Content-language
header as list of tokens.
All present Content-language
headers are merged.
Raises Not_found
when there is no Content-language
header.
val set_content_language : #Nethttp.http_header -> string list -> unit
Content-language
headerval get_content_length : #Nethttp.http_header_ro -> int64
Content-length
header as number. If the number
is too big for int64, the exception Bad_header_field
"Content-length"
will be raised.
Not_found
when the header is missing.val set_content_length : #Nethttp.http_header -> int64 -> unit
Content-length
headerval get_content_location : #Nethttp.http_header_ro -> string
Content-location
header as string.
Not_found
when the header is missing.val set_content_location : #Nethttp.http_header -> string -> unit
Content-location
headerval get_content_md5 : #Nethttp.http_header_ro -> string
Content-MD5
header as string. The Base64 encoding
has not been touched.
Not_found
when the header is missing.val set_content_md5 : #Nethttp.http_header -> string -> unit
Content-MD5
headerval get_content_range : #Nethttp.http_header_ro ->
[ `Bytes of (int64 * int64) option * int64 option ]
Content-range
header as
`Bytes(byte_range_resp_spec, instance_length)
. The option value
None
corresponds to "*" in the RFC.
Not_found
when the header is missing.val set_content_range : #Nethttp.http_header ->
[ `Bytes of (int64 * int64) option * int64 option ] -> unit
Content-range
headerval get_content_type : #Nethttp.http_header_ro -> string * (string * string) list
Content-type
header as pair (media_type, params)
.
Not_found
when the header is missing.val set_content_type : #Nethttp.http_header -> string * (string * string) list -> unit
Content-type
headerval get_date : #Nethttp.http_header_ro -> float
Date
header as number (seconds since the Epoch).
Not_found
when the header is missing.val set_date : #Nethttp.http_header -> float -> unit
Date
headerval get_etag : #Nethttp.http_header_ro -> Nethttp.etag
Etag
header.
Not_found
when the header is missing.val set_etag : #Nethttp.http_header -> Nethttp.etag -> unit
Etag
headerval get_expect : #Nethttp.http_header_ro ->
(string * string option * (string * string) list) list
Expect
header as list of triples (token,value,params)
.
All present Expect
headers are merged.
Raises Not_found
when there is no Expect
header.
val set_expect : #Nethttp.http_header ->
(string * string option * (string * string) list) list -> unit
Expect
headerval get_expires : #Nethttp.http_header_ro -> float
Expires
header as number (seconds since the Epoch).
Not_found
when the header is missing.val set_expires : #Nethttp.http_header -> float -> unit
Expires
headerval get_from : #Nethttp.http_header_ro -> string
From
header as string.
Not_found
when the header is missing.val set_from : #Nethttp.http_header -> string -> unit
From
headerval get_host : #Nethttp.http_header_ro -> string * int option
Host
header as pair (host,port)
.
Not_found
when the header is missing.val set_host : #Nethttp.http_header -> string * int option -> unit
Host
headerval get_if_match : #Nethttp.http_header_ro -> Nethttp.etag list option
If-match
header. The value None
means "*".
Not_found
when the header is missing.val set_if_match : #Nethttp.http_header -> Nethttp.etag list option -> unit
If-match
headerval get_if_modified_since : #Nethttp.http_header_ro -> float
If-modified-since
header as number (seconds
since the Epoch).
Not_found
when the header is missing.val set_if_modified_since : #Nethttp.http_header -> float -> unit
If-modified-since
headerval get_if_none_match : #Nethttp.http_header_ro -> Nethttp.etag list option
If-none-match
header. The value None
means "*".
Not_found
when the header is missing.val set_if_none_match : #Nethttp.http_header -> Nethttp.etag list option -> unit
If-none-match
headerval get_if_range : #Nethttp.http_header_ro -> [ `Date of float | `Etag of Nethttp.etag ]
If-range
header.
Not_found
when the header is missing.val set_if_range : #Nethttp.http_header -> [ `Date of float | `Etag of Nethttp.etag ] -> unit
If-range
headerval get_if_unmodified_since : #Nethttp.http_header_ro -> float
If-unmodified-since
header as number (seconds
since the Epoch).
Not_found
when the header is missing.val set_if_unmodified_since : #Nethttp.http_header -> float -> unit
If-unmodified-since
headerval get_last_modified : #Nethttp.http_header_ro -> float
Last-modified
header as number (seconds since the Epoch).
Not_found
when the header is missing.val set_last_modified : #Nethttp.http_header -> float -> unit
Last-modified
headerval get_location : #Nethttp.http_header_ro -> string
Location
header as string.
Not_found
when the header is missing.val set_location : #Nethttp.http_header -> string -> unit
Location
headerval get_max_forwards : #Nethttp.http_header_ro -> int
Max-forwards
header as number.
Not_found
when the header is missing.val set_max_forwards : #Nethttp.http_header -> int -> unit
Max-forwards
headerval get_pragma : #Nethttp.http_header_ro -> (string * string option) list
Pragma
header as list of pairs (token,value)
.
All present Pragma
headers are merged.
Raises Not_found
when there is no Pragma
header.
val set_pragma : #Nethttp.http_header -> (string * string option) list -> unit
Pragma
headerval get_proxy_authenticate : #Nethttp.http_header_ro -> auth_challenge list
Proxy-authenticate
header as list of challenges
(auth_scheme,auth_params)
. See also get_www_authenticate
.
All present Proxy-authenticate
headers are merged.
Raises Not_found
when there is no Proxy-authenticate
header.
At present, parameters are always decoded (`V
).
val set_proxy_authenticate : #Nethttp.http_header -> auth_challenge list -> unit
Proxy-authenticate
header#Nethttp.http_header_ro -> auth_credentials
: Proxy-authorization
header as pair
(auth_scheme,auth_params)
.Not_found
when the header is
missing.
The "Basic" authentication scheme is represented specially as
("basic", [ "credentials", creds ])
where creds
are the
Base64-encoded credentials.
At present, parameters are always decoded (`V
).
#Nethttp.http_header -> auth_credentials -> unit
: Proxy-authorization
header
The "Basic" authentication scheme is represented as explained for
get_proxy_authorization
.val get_range : #Nethttp.http_header_ro -> [ `Bytes of (int64 option * int64 option) list ]
Range
header as `Bytes ranges
, where the list ranges
has elements of the form (Some first_pos, Some last_pos)
,
(Some first_pos, None)
(prefix range), or (None, Some
last_pos)
(suffix range).
Not_found
when the header is missing.val set_range : #Nethttp.http_header ->
[ `Bytes of (int64 option * int64 option) list ] -> unit
Range
headerval get_referer : #Nethttp.http_header_ro -> string
Referer
header as string.
Not_found
when the header is missing.val get_referrer : #Nethttp.http_header_ro -> string
val set_referer : #Nethttp.http_header -> string -> unit
Referer
headerval set_referrer : #Nethttp.http_header -> string -> unit
val get_retry_after : #Nethttp.http_header_ro -> [ `Date of float | `Seconds of int ]
Retry-after
header.
Not_found
when the header is missing.val set_retry_after : #Nethttp.http_header -> [ `Date of float | `Seconds of int ] -> unit
Retry-after
headerval get_server : #Nethttp.http_header_ro -> string
Server
header as uninterpreted string (including
comments).
Not_found
when the header is missing.val set_server : #Nethttp.http_header -> string -> unit
Server
headerval get_te : #Nethttp.http_header_ro ->
(string * (string * string) list * (string * string) list) list
TE
header as list of triples
(te_token, te_params, accept_params)
.
If there are accept_params
, the first such parameter is always "q"
.
All present TE
headers are merged. The function returns []
when
there is at least one TE
header, but none of the headers has a
non-empty value.
Raises Not_found
if there no such headers at all.
val set_te : #Nethttp.http_header ->
(string * (string * string) list * (string * string) list) list -> unit
TE
headerval get_trailer : #Nethttp.http_header_ro -> string list
Trailer
header as list of field names.
All present Trailer
headers are merged. The function returns
[]
when there is at least one Trailer
header, but none of
the headers has a non-empty value.
Raises Not_found
if there no such headers at all.
val set_trailer : #Nethttp.http_header -> string list -> unit
Trailer
headerval get_transfer_encoding : #Nethttp.http_header_ro -> (string * (string * string) list) list
Transfer-encoding
header as list of pairs
(token, params)
.
All present Transfer-encoding
headers are merged. The
function returns []
when there is at least one
Transfer-encoding
header, but none of the headers has a
non-empty value.
Raises Not_found
if there no such headers at all.
val set_transfer_encoding : #Nethttp.http_header -> (string * (string * string) list) list -> unit
Transfer-encoding
headerval get_upgrade : #Nethttp.http_header_ro -> string list
Upgrade
header as list of products.
All present Upgrade
headers are merged. The function returns
[]
when there is at least one Upgrade
header, but none of
the headers has a non-empty value.
Raises Not_found
if there no such headers at all.
val set_upgrade : #Nethttp.http_header -> string list -> unit
Upgrade
headerval get_user_agent : #Nethttp.http_header_ro -> string
User-agent
header as uninterpreted string
(including comments).
Not_found
if the header is missing.val set_user_agent : #Nethttp.http_header -> string -> unit
User-agent
headerval get_vary : #Nethttp.http_header_ro -> [ `Fields of string list | `Star ]
Vary
header.
Not_found
if the header is missing.val set_vary : #Nethttp.http_header -> [ `Fields of string list | `Star ] -> unit
Vary
headerval get_www_authenticate : #Nethttp.http_header_ro -> auth_challenge list
WWW-Authenticate
header as list of challenges
(auth_scheme,auth_params)
.
All present WWW-Authenticate
headers are merged.
The scheme "negotiate" uses a deviating header format.
This data is returned as e.g. ("negotiate", ["credentials", data])
.
At present, parameters are always decoded (`V
).
Raises Not_found
if the header is missing.
val set_www_authenticate : #Nethttp.http_header -> auth_challenge list -> unit
WWW-Authenticate
header#Nethttp.http_header_ro -> (string * string) list
: #Nethttp.http_header_ro -> Nethttp.Cookie.t list
: Nethttp.Cookie.t
representation
(the suffix "_ct" reminds of Cookie.t
).
This function also supports version 1 cookies.
Returns the empty list if there are no cookies.#Nethttp.http_header -> (string * string) list -> unit
: Cookie
header. Note: This does not set cookies in the client,
use set_set_cookie
instead!#Nethttp.http_header_ro -> Nethttp.netscape_cookie list
: Set-Cookie
header#Nethttp.http_header -> Nethttp.netscape_cookie list -> unit
: Set-Cookie
header#Nethttp.http_header -> Nethttp.Cookie.t list -> unit
: Set-Cookie
and Set-Cookie2
headers:
set_set_cookie_ct header cookies
sets the cookies
in header
using version 0 or version 1 depending on whether version 1
fields are used. For better browser compatibility, if
"Set-cookie2" (RFC 2965) is issued, then a "Set-cookie"
precedes (declaring the same cookie with a limited number of
options).