View Source CookieMonster (CookieMonster v1.1.2)
A simple HTTP Cookie encoder and decoder written in pure Elixir with zero dependencies.
Follows the standards for cookie headers described in MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
Summary
Functions
Decodes a Set-Cookie header text into an Elixir struct
Decodes a Set-Cookie Header into an Elixir struct
See CookieMonster.Encoder.encode/1
.
Encodes a cookie struct into a header string
Functions
@spec decode(String.t()) :: CookieMonster.Decoder.return_t()
Decodes a Set-Cookie header text into an Elixir struct
Example
iex> header = "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly"
...> {:ok, cookie} = CookieMonster.decode(header)
...> cookie
%CookieMonster.Cookie{
value: "a3fWa",
expires: ~U[2015-10-21 07:28:00Z],
http_only: true,
name: "id",
secure: true
}
@spec decode!(String.t()) :: CookieMonster.Cookie.t()
Decodes a Set-Cookie Header into an Elixir struct
Similar to decode/1
except it will unwrap the error tuple and raise
in case of errors.
See CookieMonster.Encoder.encode/1
.
@spec encode( CookieMonster.Cookie.t() | map(), keyword() ) :: CookieMonster.Encoder.return_t()
Encodes a cookie struct into a header string
Example
iex> cookie = %CookieMonster.Cookie{
...> name: "id",
...> value: "a3fWa",
...> expires: ~U[2015-10-21 07:28:00Z],
...> http_only: true,
...> secure: true
...> }
iex> CookieMonster.encode(cookie)
{:ok, "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; HttpOnly; Secure"}