Module Opium.Cookie
Cookie management for both requests and responses.
module Signer : sig ... endSign an unsign cookies with secret.
type expires=[|`Session|`Max_age of int64|`Date of Ptime.t]expiresdescribes when a cookie will expire.`Session- nothing will be set`Max_age- Max-Age will be set with the number`Date- Expires will be set with a date
type same_site=[|`None|`Strict|`Lax]type value= string * stringThe value of a cookie is a tuple of
(name, value)
type t={expires : expires;scope : Uri.t;same_site : same_site;secure : bool;http_only : bool;value : value;}
Constructors
make
val make : ?expires:expires -> ?scope:Uri.t -> ?same_site:same_site -> ?secure:bool -> ?http_only:bool -> ?sign_with:Signer.t -> value -> tmake cookiecreates a cookie with the key-value paircookieIt will default to the following values:
Note that if no value is given for
scope, the browsers might use a default value. For instance, if the cookie is set from the response ofhttp://example.com/users/loginand does not specify a scope, some browsers will use/usersas a scope. If you want the cookie to be valid for every endpoint of your application, you need to use"/"as the scope of your cookie.
of_set_cookie_header
to_set_cookie_header
Encoders
to_set_cookie_header
to_cookie_header
Decoders
cookie_of_header
val cookie_of_header : ?signed_with:Signer.t -> string -> header -> value optioncookie_of_header ?signed_with key headerreturns the value of a the cookie with the keykeyin the headerheader.If the cookie with the key
keydoes not exist, or if the header is not a validCookieheader,Nonewill be returned.
cookies_of_header
cookie_of_headers
val cookie_of_headers : ?signed_with:Signer.t -> string -> header list -> value optioncookie_of_headers ?signed_with key headersreturns the value of a the cookie with the keykeyin the headersheaders.If the cookie with the key
keydoes not exist, or if no header is not a validCookieheader,Nonewill be returned.
cookies_of_headers
Utilities
sexp_of_t
val sexp_of_t : t -> Sexplib0.Sexp.tsexp_of_t tconverts the cookietto an s-expression.
pp
val pp : Stdlib.Format.formatter -> t -> unitppformats the cookietas an s-expression.