@eryx/http/CookieJar Module

JSON

A cookie jar that stores cookies and automatically attaches them to matching requests.

local jar = http.CookieJar.new()

-- Make requests with automatic cookie handling
local resp = http.get("http://example.com/login", { cookies = jar })
-- jar now contains any Set-Cookie headers from the response

-- Subsequent requests send matching cookies automatically
local resp2 = http.get("http://example.com/dashboard", { cookies = jar })

Summary

Classes

_cookies: { cookies.Cookie }
CookieJar:parseSetCookie(setCookieHeader: string, requestHost: string, requestPath: string)()
CookieJar:getCookies(scheme: string, host: string, path: string){ cookies.Cookie }
CookieJar:headerFor(scheme: string, host: string, path: string)string?
CookieJar:count()number

API Reference

Classes

CookieJar

Properties

_cookies: { cookies.Cookie }

CookieJar.new

Creates a new, empty cookie jar.

CookieJar.new()CookieJar

Returns

A new cookie jar.

CookieJar:parseSetCookie

Stores cookies from a Set-Cookie response header.

Parses the header value and stores the cookie with proper domain and path defaults derived from the request URL. Existing cookies with the same name/domain/path are replaced.

CookieJar:parseSetCookie(setCookieHeader: string, requestHost: string, requestPath: string)()

Parameters

setCookieHeader: string

The raw Set-Cookie header value.

requestHost: string

The host the request was sent to.

requestPath: string

The path the request was sent to.

CookieJar:getCookies

Returns all cookies that match the given URL components.

Expired cookies are automatically removed. Only cookies whose domain and path match the request are returned.

CookieJar:getCookies(scheme: string, host: string, path: string){ cookies.Cookie }

Parameters

scheme: string

The request scheme ("http" or "https").

host: string

The request host.

path: string

The request path.

Returns

{ cookies.Cookie }

Matching cookies.

CookieJar:headerFor

Builds the Cookie header string for a request to the given URL.

CookieJar:headerFor(scheme: string, host: string, path: string)string?

Parameters

scheme: string

The request scheme.

host: string

The request host.

path: string

The request path.

Returns

string?

The Cookie header value, or nil if no cookies match.

CookieJar:count

Returns the number of cookies stored in the jar.

CookieJar:count()number

Returns

number

The cookie count.

CookieJar:clear

Removes all cookies from the jar.

CookieJar:clear()()