Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Cookie
SourceThe Cookie
module implements HTTP Cookies sent in a 'Cookie' header in a http request or 'Set-Cookie' headers added in a http response.
The module closely follows the HTTP Cookie specification as defined in RFC6265 https://tools.ietf.org/html/rfc6265
.
Represents either a Cookie name-value in 'Cookie' request header or a set of cookie attributes in 'Set-Cookie' response header.
type error = private [>
| `Cookie_name_error of string
Denotes 'cookie name' validation and parsing errors.
*)| `Cookie_value_error of string
Denotes 'cookie value' validation and parsing errors.
*)| `Cookie_domain_av_error of string
Denotes 'cookie domain' attribue value validation and parsing errors.
*)| `Cookie_path_error of string
Denotes 'cookie path' attribute value validation and parsing errors.
*)| `Cookie_max_age_error of string
Denotes 'cookie max-age' attribute value validation errors.
*)| `Cookie_extension_error of string
Denotes 'cookie extension' attribute value validation errors.
*) ]
val create :
name:string ->
value:string ->
?sanitize_name:bool ->
?sanitize_value:bool ->
?path:string ->
?domain:string ->
?expires:Ptime.t ->
?max_age:int ->
?secure:bool ->
?http_only:bool ->
?same_site:Same_site.t ->
?extension:string ->
unit ->
(t, error) result
create ... ()
parse a cookie instance t
from given value parameters. If the given values parses successfully, then Ok t
is returned. If an error is encountered while parsing then an Error err
is returned.
~sanitize_value
if true then value
is double quoted if it starts or ends in a ' '(space) or a ','(comma) character.
~sanitize_name
if true and name
contains '\n' or '\r' character then it is replaced by '-' character.
name t
returns a cookie name. See https://tools.ietf.org/html/rfc6265#section-4.1.1 'cookie-name' definition for details.
value t
returns a cookie value. See 'cookie-value' definition in https://tools.ietf.org/html/rfc6265#section-4.1.1
path t
returns cookie path attribute. See https://tools.ietf.org/html/rfc6265#section-5.2.4
domain t
returns cookie domain attribute. See https://tools.ietf.org/html/rfc6265#section-4.1.2.3
expires t
returns a coookie expires attribute. See https://tools.ietf.org/html/rfc6265#section-4.1.2.1.
Additionally, the date format followed is as specified in https://tools.ietf.org/html/rfc2616#section-3.3.1
max_age t
returns a cookie max_age attribute. See https://tools.ietf.org/html/rfc6265#section-4.1.2.2.
Additionally, see 'max-age-av' in https://tools.ietf.org/html/rfc6265#section-4.1.1
secure t
returns a secure attribute. See https://tools.ietf.org/html/rfc6265#section-4.1.2.5
http_only t
returns a http_only attribute. See https://tools.ietf.org/html/rfc6265#section-4.1.2.6
same_site t
returns a same_site attribute. See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00.
extension t
returns a cookie extension value. See k https://tools.ietf.org/html/rfc6265#section-4.1.1
of_cookie_header s
parses s
- a string value which represents HTTP 'Cookie' header value as defined in https://tools.ietf.org/html/rfc6265#section-4.2 and returns a list of Cookie
s. Examples of s
is SID=31d4d96e407aad42; lang=en-US
. Here we define 2 cookies 'SID' and 'lang-en'.
to_set_header c
serializes c
into a string which can be used as value for HTTP 'Set-Cookie' header.