Skip to content

Cookie jar for HTTP client #73

Description

@lalinsky

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    wishlistSomething that would be nice to have, but not planned right now

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions