Skip to content

Add cookie jar for automatic cookie management#10

Draft
carpentry-agent[bot] wants to merge 1 commit into
mainfrom
claude/cookie-jar
Draft

Add cookie jar for automatic cookie management#10
carpentry-agent[bot] wants to merge 1 commit into
mainfrom
claude/cookie-jar

Conversation

@carpentry-agent

Copy link
Copy Markdown

Summary

Adds a CookieJar type and jar-aware Client functions that automatically store cookies from Set-Cookie response headers and replay matching cookies on subsequent requests.

New module: CookieJar

  • create / store! / store-response! / clear! — manage cookie storage
  • matching / cookie-header / apply-to-headers — match cookies by domain (suffix), path (prefix), Secure flag, and expiry
  • Deduplicates cookies by name + domain + path; defaults domain from request URL when Set-Cookie omits it

New Client functions

  • request-with-jar / request-stream-with-jar — core jar-aware request functions with redirect support
  • get-with-jar, head-with-jar, post-with-jar, put-with-jar, del-with-jar, patch-with-jar — convenience wrappers
  • request-with-jar-and-config / request-stream-with-jar-and-config — config-aware variants

The jar integrates into the redirect loop: cookies from every response (including redirects) are stored, and correct cookies are re-applied for each new URL. Cross-origin redirect header stripping still applies to user-supplied headers; the jar then re-applies domain-appropriate cookies.

Why: Without a cookie jar, any session-based or auth-cookie workflow requires manual cookie management. The http library already has a Cookie type with parse-set support, but the client side had no automatic cookie handling.

Tests: 20+ unit tests for jar operations (storage, dedup, domain matching, path matching, secure flag, header generation) plus integration tests against httpbin.org.

Note: The existing C compilation issue with time library's tm_zone field (pre-existing, affects all builds) prevents running the test binary. All Carp-level type checking passes cleanly.


Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.

Introduces CookieJar type that stores cookies from Set-Cookie response
headers and automatically replays matching cookies on subsequent requests.
Cookies are matched by domain (suffix), path (prefix), Secure flag, and
expiry. Adds jar-aware Client functions (get-with-jar, post-with-jar, etc.)
that integrate cookie handling into the redirect loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants