package vif

  1. Overview
  2. Docs

Module Vif.CookieSource

Cookies

get and set are designed for round-tripping secure cookies. The most secure settings applicable to the current server are inferred automatically.

let hello req server _ =
  let open Vif.Response.Syntax in
  let value = Vif.Cookie.get ~name:"my-cookie" server req in
  match value with
  | "ping" ->
      let* () = Vif.Cookie.set ~name:"my-cookie" server req "pong" in
      Vif.Response.respond `OK
  | "pong" ->
      let* () = Vif.Cookie.set ~name:"my-cookie" server req "ping" in
      Vif.Response.respond `OK
  | _ -> Vif.Response.respond `OK
Sourcetype config
Sourceval config : ?expires:float -> ?max_age:float -> ?domain:[ `host ] Domain_name.t -> ?path:bool -> ?secure:bool -> ?http_only:bool -> ?same_site:[ `Lax | `Strict | `None ] -> unit -> config
Sourcetype error = [
  1. | `Msg of string
  2. | `Not_found
]
Sourceval get : ?encrypted:bool -> name:string -> Server.t -> Request.request -> (string, [> error ]) result

get ?encrypted ~name server req returns the value associated to the key name from cookies. By default, cookies are encrypted.

Sourceval pp_error : error Fmt.t

Pretty printer of errors.

Sourceval set : ?encrypt:bool -> ?cfg:config -> ?path:string -> name:string -> Server.t -> ('c, 'a) Request.t -> string -> ('p, 'p, unit) Response.t

set ?encrypt ?cfg ?path ~name server req value creates a new cookie name on the client side with the value value that can be retrieved with get afterwards. By default, the cookie is encrypted.