gleam/http/cookie

Types

Attributes

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

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

Constructors

  • Attributes( max_age: Option(Int), domain: Option(String), path: Option(String), secure: Bool, http_only: Bool, same_site: Option(SameSitePolicy), )

SameSitePolicy

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

Functions

default_attributes

pub fn default_attributes() -> Attributes

Helper to create sensible default attributes for a set cookie.

NOTE these defaults ensure you cookie is always available to you application. However this is not a fully secure solution. You should consider setting a Secure and/or SameSite attribute.

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

empty_attributes

pub fn empty_attributes() -> Attributes

Helper to create empty Attributes for a cookie.

expire_attributes

pub fn expire_attributes(attributes: Attributes) -> Attributes

Update the MaxAge of a set of attributes to 0. This informes the client that the cookie should be expired.

pub fn set_cookie_string(
  name: String,
  value: String,
  attributes: Attributes,
) -> String

Serialize a cookie and attributes.

This is the serialization of a cookie for the set-cookie header