package sihl

  1. Overview
  2. Docs
The modular functional web framework

Install

Dune Dependency

Authors

Maintainers

Sources

sihl-queue-0.1.9.tbz
sha256=77f0813d75a88edd14b3396e8b848d94c31c28803299b4b1bd4b78b1de4a2e80
sha512=a8907bc35ea14b7c3a7d638979a2a274860202b2de58b84b5621a4908db001ace493d8aa2e5383f4c8b1847efd256938592f63ef75a41521284b3640d3a7442a

doc/sihl.http/Sihl_http/Cookie/index.html

Module Sihl_http.CookieSource

Cookie management for both requests and responses.

Sourcemodule Signer : sig ... end

Sign an unsign cookies with secret.

Sourcetype header = string * string

A single header represented as a key-value pair.

Sourcetype expires = [
  1. | `Session
  2. | `Max_age of int64
  3. | `Date of Ptime.t
]

expires describes 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
Sourcetype same_site = [
  1. | `None
  2. | `Strict
  3. | `Lax
]
Sourcetype value = string * string

The value of a cookie is a tuple of (name, value)

Sourcetype t = {
  1. expires : expires;
  2. scope : Uri.t;
  3. same_site : same_site;
  4. secure : bool;
  5. http_only : bool;
  6. value : value;
}
Sourceval value : t -> value

Constructors

make

Sourceval make : ?expires:expires -> ?scope:Uri.t -> ?same_site:same_site -> ?secure:bool -> ?http_only:bool -> ?sign_with:Signer.t -> value -> t

make cookie creates a cookie with the key-value pair cookie

It 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 of http://example.com/users/login and does not specify a scope, some browsers will use /users as 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 ?signed_with ?origin header creates a cookie from a Set-Cookie header header.

If the header is not a valid Set-Cookie header, None is returned.

Encoders

to_set_cookie_header t creates an HTTP header for the cookie t.

to_cookie_header ?now ?elapsed ?scope cookies creates an HTTP header for the list of cookies cookies.

Decoders

cookie_of_header ?signed_with key header returns the value of a the cookie with the key key in the header header.

If the cookie with the key key does not exist, or if the header is not a valid Cookie header, None will be returned.

cookies_of_header

Sourceval cookies_of_header : ?signed_with:Signer.t -> header -> value list

cookies_of_header ?signed_with header returns the list of cookie values in the header header.

If the header is not a valid Cookie header, an empty list is returned.

cookie_of_headers ?signed_with key headers returns the value of a the cookie with the key key in the headers headers.

If the cookie with the key key does not exist, or if no header is not a valid Cookie header, None will be returned.

cookies_of_headers

Sourceval cookies_of_headers : ?signed_with:Signer.t -> header list -> value list

cookies_of_headers ?signed_with headers returns the list of cookie values in the headers headers.

If no header is not a valid Cookie header, an empty list is returned.

Utilities

sexp_of_t

Sourceval sexp_of_t : t -> Sexplib0.Sexp.t

sexp_of_t t converts the cookie t to an s-expression.

pp

Sourceval pp : Format.formatter -> t -> unit

pp formats the cookie t as an s-expression.

OCaml

Innovation. Community. Security.