HttpCookie (http_cookie v0.7.0)

View Source

HTTP Cookie struct with parsing and related logic.

Implemented according to RFC6265

Summary

Functions

Checks if the cookie has expired.

Creates an HttpCookie from a Set-Cookie header value.

Checks if the cookie matches the provided request url.

Formats the cookie for sending in a "Cookie" header.

Updates the cookie last access time.

Types

t()

@type t() :: %HttpCookie{
  creation_time: DateTime.t(),
  domain: binary(),
  expiry_time: DateTime.t(),
  host_only?: boolean(),
  http_only?: boolean(),
  last_access_time: DateTime.t(),
  name: binary(),
  path: binary(),
  persistent?: boolean(),
  secure_only?: boolean(),
  value: binary()
}

Functions

expired?(cookie, now \\ DateTime.utc_now())

@spec expired?(cookie :: t(), now :: DateTime.t()) :: boolean()

Checks if the cookie has expired.

Uses the current time if no time is provided.

matches_url?(cookie, request_url)

@spec matches_url?(cookie :: t(), request_url :: URI.t()) :: boolean()

Checks if the cookie matches the provided request url.

The check is done as specified in RFC 6265.

to_header_value(cookie)

@spec to_header_value(cookie :: t()) :: String.t()

Formats the cookie for sending in a "Cookie" header.

update_last_access_time(cookie, now \\ DateTime.utc_now())

@spec update_last_access_time(cookie :: t(), DateTime.t()) :: t()

Updates the cookie last access time.

Uses the current time if no time is provided.