A cookie jar used to seed the initial request of a test and to track cookies across subsequent requests. Supports:
setSessionSet-Cookie response headers to capture cookies and their
attributes (Path, Domain, Expires, Max-Age, Secure, HttpOnly, SameSite)
across requestsTest.BackendTask.TestSetup
via withCookiesA cookie with its value and attributes as parsed from Set-Cookie.
Attributes default to unset/false when a cookie is added via set or
setSession. withSetCookieHeaders
populates attributes from response headers.
expires is preserved as the raw header string (date formats vary). sameSite
is the raw attribute value ("Strict", "Lax", or "None").
An empty cookie jar, ready for set and
setSession.
Set a cookie in the jar with the given name and value. Attributes default
to unset/false; use withSetCookieHeaders to capture
attributes from a response.
Set a signed session cookie in the jar. The Session
value is encoded and signed the same way
Server.Session encodes its payload at runtime, so routes
reading the cookie get the seeded values back out.
import Test.PagesProgram.CookieJar as CookieJar
import Test.PagesProgram.Session as Session
CookieJar.init
|> CookieJar.setSession
{ name = "mysession"
, secret = "test-secret"
, session =
Session.init
|> Session.withValue "userId" "42"
}The secret is recorded alongside the signed cookie so the visual test
runner can surface which secret produced each signed cookie. The test mock
does not use real HMAC, so secret may be any non-empty string without .
characters.
Get a cookie's full entry (value + attributes) from the jar.
Convert the cookie jar to a Dict of name/value pairs for use in request construction. Attributes are dropped — requests only need name/value.
List every cookie in the jar with its full entry.
Apply a list of Set-Cookie header values to the cookie jar. Parses each
header to extract the cookie name, value, and attributes (Path, Domain,
Expires, Max-Age, Secure, HttpOnly, SameSite). Unknown attributes
are ignored.
CookieJar.init
|> CookieJar.withSetCookieHeaders
[ "session=abc123; Path=/; HttpOnly"
, "theme=dark"
]
|> CookieJar.get "session"
-- Just "abc123"Apply the jar to a Test.BackendTask.TestSetup,
seeding every cookie in the jar on the initial request.
import Test.BackendTask as BackendTaskTest
import Test.PagesProgram.CookieJar as CookieJar
BackendTaskTest.init
|> CookieJar.withCookies
(CookieJar.init
|> CookieJar.set "theme" "dark"
)
A collection of cookies maintained across HTTP requests.