Add cookie jar for automatic cookie management#10
Draft
carpentry-agent[bot] wants to merge 1 commit into
Draft
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
CookieJartype and jar-awareClientfunctions that automatically store cookies fromSet-Cookieresponse headers and replay matching cookies on subsequent requests.New module:
CookieJarcreate/store!/store-response!/clear!— manage cookie storagematching/cookie-header/apply-to-headers— match cookies by domain (suffix), path (prefix), Secure flag, and expirySet-Cookieomits itNew
Clientfunctionsrequest-with-jar/request-stream-with-jar— core jar-aware request functions with redirect supportget-with-jar,head-with-jar,post-with-jar,put-with-jar,del-with-jar,patch-with-jar— convenience wrappersrequest-with-jar-and-config/request-stream-with-jar-and-config— config-aware variantsThe 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
httplibrary already has aCookietype withparse-setsupport, 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
timelibrary'stm_zonefield (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.