cookie v0.1.2 Cookie

Link to this section Summary

Functions

Parse cookies as given in a cookie header.

Serialize cookies to format for cookie header.

Link to this section Functions

Parse cookies as given in a cookie header.

Examples

iex> parse("key1=value1, key2=value2")
%{"key1" => "value1", "key2" => "value2"}

# TODO check the occasions when cookies separated by semi-colon
iex> parse("key1=value1; key2=value2")
%{"key1" => "value1", "key2" => "value2"}

# `$` is invalid lead character for cooke, comment?
# Invalid cookies are dropped
iex> parse("$key1=value1, key2=value2; $key3=value3")
%{"key2" => "value2"}

# Spaces in a cookie key are invalid
iex> parse("key space=value")
%{}

# Spaces in a cookie value are preserved
iex> parse("key=value space")
%{"key" => "value space"}

# Other spaces are cleaned
iex> parse("  key1=value1 , key2=value2  ")
%{"key1" => "value1", "key2" => "value2"}

# Empty cookie string returns no cookies
iex> parse("")
%{}

iex> parse("key, =, value")
%{}

# Cookie value can be empty string
iex> parse("key=")
%{"key" => ""}

iex> parse("key1=;;key2=")
%{"key1" => "", "key2" => ""}
Link to this function

serialize(cookies)

Serialize cookies to format for cookie header.

Examples

# Can serialize individual cookie
iex> serialize({"key1", "value1"})
"key1=value1"

# Cookie value can be empty string
iex> serialize({"key1", ""})
"key1="

# Can serialize collection of cookies
iex> serialize(%{"key1" => "value1", "key2" => "value2"})
"key1=value1; key2=value2"

Be nice to property test serialize and parse.