These definitions can be used by both HTTP clients and servers, and by protocols in the middle, e.g. CGI.
A pair of a major and minor version number
The base protocol. RFC 2145 defines how to interpret major and minor numbers. In particular, we have:
`Http((0,9),_) is the ancient HTTP version 0.9`Http((1,n),_) is the HTTP protocol 1.n. It is expected that
all these versions are compatible to each other
except negotiable features.`Http((m,_),_) for m>1 is regarded as unknown protocol,
incompatible to any `Http((1,n),_)`Other is anything else (unrecognizes protocol)Returns the string representation, e.g. "HTTP/1.0". Fails for `Other
Parses the protocol string, e.g. "HTTP/1.0". Returns `Other
for unrecognized strings
HTTP response status:
Informational (1xx):
`Continue`Switching_protocolsSuccessful (2xx):
`Ok`Created`Accepted`Non_authoritative`No_content`Reset_content`Partial_contentRedirection (3xx):
`Multiple_choices`Moved_permanently`Found`See_other`Not_modified`Use_proxy`Temporary_redirectClient error (4xx):
`Bad_request`Unauthorized`Payment_required`Forbidden`Not_found`Method_not_allowed`Not_acceptable`Proxy_auth_required`Request_timeout`Conflict`Gone`Length_required`Precondition_failed`Request_entity_too_large`Request_uri_too_long`Unsupported_media_type`Request_range_not_satisfiable`Expectation_failedServer Error (5xx):
`Internal_server_error`Not_implemented`Bad_gateway`Service_unavailable`Gateway_timeout`Http_version_not_supportedReturns the status value for an integer code, or raises Not_found
Allows to handle unknown status codes that are untranslatable by
http_status_of_int:
E.g.
let st =
try Nethttp.http_status_of_int code
with Not_found ->
Nethttp.http_status_of_int (Nethttp.base_code code)
Method name, URI
The cache control token for the Cache-control header
Entity tags can be weak or strong
Raised when a header field cannot be parsed. The string argument is the name of the failing function
Returns the status code and the status text corresponding to the
Status header
|
#
cookie_name
| : string | ; | (* | The name of the cookie | *) |
|
#
cookie_value
| : string | ; | (* | The value of the cookie. There are no restrictions on the value of the cookie | *) |
|
#
cookie_expires
| : float option | ; | (* | Expiration:
| *) |
|
#
cookie_domain
| : string option | ; | (* | Cookies are bound to a certain domain, i.e. the browser sends
them only when web pages of the domain are requested:
| *) |
|
#
cookie_path
| : string option | ; | (* | Cookies are also bound to certain path prefixes, i.e. the browser
sends them only when web pages at the path or below are requested.
| *) |
|
#
cookie_secure
| : bool | ; | (* | Cookies are also bound to the type of the web server:
false means servers without SSL, true means servers with
activated SSL ("https"). | *) |
Splits the URI into a "script name" and a "query string"
Splits the Host header in hostname and optional port number.
Fails on syntax error
Encodes unsafe characters in URI paths. The slash character is not encoded. This function should only be applied to the part before '?'.
Decodes %XX sequences in URI paths. %2F is forbidden (failure). This function should only be applied to the part before '?'.
Functions to manipulate cookies.
You should know that besides the name and value attribute,
user agents will send at most the path, domain and port and
usually will not send them at all.
For interoperability, cookies are set using version 0 (by Netscape) unless version 1 (RFC 2965 and the older RFC 2109) fields are set. While version 0 is well supported by browsers, RFC 2109 requires a recent browser and RFC 2965 is usually not supported. You do not have to worry however, cookies are always sent in such a way older browsers understand them -- albeit not all attributes of course -- so your application can be ready for the time RFC 2965 will be the norm.
This cookie representation is preferred over the Netscape-only type Nethttp.netscape_cookie.
N.B. This module appears also as Netcgi.Cookie.
Mutable cookie type
make ?expires ?domain ?path ?secure name value creates a new
cookie with name name holding value.
false.
"".
"".
port c the ports to which the cookie may be returned or [] if
not set.
The expiration time of the cookie, in seconds. None means
that the cookie will be discarded when the browser exits.
This information is not returned by the browser.
Tells whether the cookie is secure. This information is not returned by the browser.
Returns the comment associated to the cookie or "" if it
does not exists. This information is not returned by the
browser.
Returns the comment URL associated to the cookie or "" if it
does not exists. This information is not returned by the
browser.
set_max_age c (Some t) sets the lifetime of the cookie c
to t seconds. If t <= 0, it means that the cookie should
be discarded immediately. set_expires c None tells the
cookie to be discarded when the user agent exits. (Despite
the fact that the name is borrowed from the version 1 of the
specification, it works transparently with version 0.)
Cookies are bound to a certain domain, i.e. the browser sends them only when web pages of the domain are requested:
None: the domain is the hostname of the server.Some domain: the domain is domain.Cookies are also bound to certain path prefixes, i.e. the browser sends them only when web pages at the path or below are requested.
None: the path is script name + path_infoSome p: the path is p. With Some "/" you can disable the
path restriction completely.Cookies are also bound to the type of the web server:
set_secure false means servers without SSL, set_secure
true means servers with activated SSL ("https").
set_comment c s sets the comment of the cookie c to s
which must be UTF-8 encoded (RFC 2279). Because cookies can
store personal information, the comment should describe how
the cookie will be used so the client can decide whether to
allow the cookie or not. To cancel a comment, set it to "".
Cookie version 1 (RFC 2109).
set_comment_url c url same as Netcgi.Cookie.set_comment
except that the cookie comment is available on the page
pointed by url. To cancel, set it to "".
Cookie version 1 (RFC 2965).
set ports c (Some p) says that the cookie c must only be
returned if the server request comes from one of the listed
ports. If p = [], the cookie will only be sent to the
request-port it was received from. set_ports c None says
that the cookie may be sent to any port.
Cookie version 1 (RFC 2965).
This module is a parser/printer for the header fields used in HTTP/1.1.
The 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.
Returns the 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 ["*/*",[],[] ]).
Returns the best media type for a header and a list of supported types. If any type is acceptable, "*/*" will be returned. If no type is acceptable, "" will be returned. The supported media types should be sorted such that the best type is mentioned first. Of several media types with equal quality the one mentioned first in the list of supported types is chosen. In case several types in the Accept: header match the same type in the list of supported types, the most specific type is chosen.
Sets the Accept header
Returns the 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 ["*",[]]).
Returns the best charset for a header and a list of supported charsets. If any charset is acceptable, "*" will be returned. The supported charsets should be sorted such that the best charset is mentioned first.
This function already implements the special handling of ISO-8859-1 mentioned in RFC 2616.
Sets the Accept-charset header
Returns the 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",[]].
Returns the best encoding for a header and a list of supported encodings. If anything else fails, "identity" will be returned. The supported encodings should be sorted such that the best encoding is mentioned first.
Sets the Accept-encoding header
Returns the 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 ["*",[]]).
Sets the Accept-language header
Returns the 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.
Returns the 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.
Returns the 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.
Sets the Authorization header.
The "Basic" authentication scheme is represented as explained for
get_authorization.
Returns the 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.
Sets the Cache-control header
Returns the 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.
Returns the Content-encoding header as list of tokens.
All present Content-encoding headers are merged.
Not_found when there is no Content-encoding header.
Returns the Content-language header as list of tokens.
All present Content-language headers are merged.
Not_found when there is no Content-language header.
Returns the 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.
Returns the Content-location header as string.
Not_found when the header is missing.
Returns the Content-MD5 header as string. The Base64 encoding
has not been touched.
Not_found when the header is missing.
Returns the 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.
Sets the Content-range header
Returns the Content-type header as pair (media_type, params).
Not_found when the header is missing.
Sets the Content-type header
Returns the Date header as number (seconds since the Epoch).
Not_found when the header is missing.
Returns the Etag header.
Not_found when the header is missing.
Returns the Expect header as list of triples (token,value,params).
All present Expect headers are merged.
Not_found when there is no Expect header.
Sets the Expect header
Returns the Expires header as number (seconds since the Epoch).
Not_found when the header is missing.
Returns the From header as string.
Not_found when the header is missing.
Returns the Host header as pair (host,port).
Not_found when the header is missing.
Returns the If-match header. The value None means "*".
Not_found when the header is missing.
Returns the If-modified-since header as number (seconds
since the Epoch).
Not_found when the header is missing.
Returns the If-none-match header. The value None means "*".
Not_found when the header is missing.
Returns the If-range header.
Not_found when the header is missing.
Sets the If-range header
Returns the If-unmodified-since header as number (seconds
since the Epoch).
Not_found when the header is missing.
Returns the Last-modified header as number (seconds since the Epoch).
Not_found when the header is missing.
Returns the Location header as string.
Not_found when the header is missing.
Returns the Max-forwards header as number.
Not_found when the header is missing.
Returns the Pragma header as list of pairs (token,value).
All present Pragma headers are merged.
Not_found when there is no Pragma header.
Returns the Proxy-authenticate header as list of challenges
(auth_scheme,auth_params).
All present Proxy-authenticate headers are merged.
Not_found when there is no Proxy-authenticate header.
Sets the Proxy-authenticate header
Returns the Proxy-authorization header as pair
(auth_scheme,auth_params).
Not_found when the header is
missing.("basic", [ "credentials", creds ]) where creds are the
Base64-encoded credentials.
Sets the Proxy-authorization header
The "Basic" authentication scheme is represented as explained for
get_proxy_authorization.
Returns the 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.
Sets the Range header
Returns the Referer header as string.
Not_found when the header is missing.
Returns the Retry-after header.
Not_found when the header is missing.
Sets the Retry-after header
Returns the Server header as uninterpreted string (including
comments).
Not_found when the header is missing.
Returns the 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.
Not_found if there no such headers at all.
Sets the TE header
Returns the 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.
Not_found if there no such headers at all.
Returns the 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.
Not_found if there no such headers at all.
Sets the Transfer-encoding header
Returns the 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.
Not_found if there no such headers at all.
Returns the User-agent header as uninterpreted string
(including comments).
Not_found if the header is missing.
Returns the Vary header.
Not_found if the header is missing.
Returns the WWW-Authenticate header as list of challenges
(auth_scheme,auth_params).
All present WWW-Authenticate headers are merged.
Not_found if the header is missing.
Sets the WWW-Authenticate header
Get the (Netscape) cookies as (name,value) pairs (or Not_found).
Set the Cookie header. Note: This does not set cookies in the client,
use set_set_cookie instead!
Set the 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).