The HTTP client is currently stateless — cookies received in Set-Cookie response headers are not stored or replayed in subsequent requests. This makes it impossible to use the client for workflows that depend on cookie-based sessions, such as testing login flows or scraping sites that require authentication.
Proposed feature
Add a CookieJar that can be optionally attached to a Client (or passed per-request via FetchOptions). It should:
- Parse and store cookies from
Set-Cookie response headers
- Replay matching cookies in the
Cookie request header on subsequent requests
- Respect cookie attributes:
Domain, Path, Expires/Max-Age, Secure, HttpOnly
- Handle cookie eviction (expired cookies are not sent)
Example usage
var jar = http.CookieJar.init(allocator);
defer jar.deinit();
var client = http.Client.init(gpa, io, .{ .cookie_jar = &jar });
defer client.deinit();
// Login — server sets a session cookie
_ = try client.fetch("http://example.com/login", .{
.method = .POST,
.body = "user=foo&pass=bar",
});
// Subsequent request automatically sends the session cookie
var res = try client.fetch("http://example.com/profile", .{});
defer res.deinit();
Scope
- A new
CookieJar struct in src/cookie.zig or a new src/cookie_jar.zig
- Integration into
client.zig: populate jar from responses, attach cookies to requests
- Thread-safety is not required initially (same assumption as the rest of the client)
The HTTP client is currently stateless — cookies received in
Set-Cookieresponse headers are not stored or replayed in subsequent requests. This makes it impossible to use the client for workflows that depend on cookie-based sessions, such as testing login flows or scraping sites that require authentication.Proposed feature
Add a
CookieJarthat can be optionally attached to aClient(or passed per-request viaFetchOptions). It should:Set-Cookieresponse headersCookierequest header on subsequent requestsDomain,Path,Expires/Max-Age,Secure,HttpOnlyExample usage
Scope
CookieJarstruct insrc/cookie.zigor a newsrc/cookie_jar.zigclient.zig: populate jar from responses, attach cookies to requests