gleam/http/cookie

Types

Attributes of a cookie when sent to a client in the set-cookie header.

pub type Attributes {
  Attributes(
    max_age: option.Option(Int),
    domain: option.Option(String),
    path: option.Option(String),
    secure: Bool,
    http_only: Bool,
    same_site: option.Option(SameSitePolicy),
  )
}

Constructors

Policy options for the SameSite cookie attribute

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite

pub type SameSitePolicy {
  Lax
  Strict
  None
}

Constructors

  • Lax
  • Strict
  • None

Values

pub fn defaults(scheme: http.Scheme) -> Attributes

Helper to create sensible default attributes for a set cookie.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#Attributes

pub fn parse(cookie_string: String) -> List(#(String, String))

Parse a list of cookies from a header string. Any malformed cookies will be discarded.

Backwards compatibility

RFC 6265 states that cookies in the cookie header should be separated by a ;, however this function will also accept a , separator to remain compatible with the now-deprecated RFC 2965, and any older software following that specification.

pub fn set_header(
  name: String,
  value: String,
  attributes: Attributes,
) -> String
Search Document