fix: add Headers.getSetCookie() and fix Set-Cookie iterator folding#149
Open
DepsCian wants to merge 1 commit into
Open
fix: add Headers.getSetCookie() and fix Set-Cookie iterator folding#149DepsCian wants to merge 1 commit into
DepsCian wants to merge 1 commit into
Conversation
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.
Fixes #148
Problem
Headers.get("set-cookie")comma-folds multipleSet-Cookievalues into a single string ("a=1, b=2"), violating RFC 6265 §3 and the Fetch spec which explicitly forbids combiningSet-Cookiefields. ThegetSetCookie()method required by the spec does not exist.This causes silent cookie loss when multiple
Set-Cookieheaders are present (e.g.__Secure-next-auth.session-token+__cf_bm) — a common pattern in NextAuth.js flows.Changes
src/wreq-js.ts— Headers class:Added
getSetCookie(): string[]— returns individualSet-Cookievalues as an array, matching the native Fetch API. Returns[]when absent.Fixed
[Symbol.iterator]— yields one[name, value]tuple perSet-Cookievalue instead of comma-folding. All other headers retain the existingvalues.join(", ")behavior.Fixed
toObject()— iteratesstore.values()directly (bypasses the multi-tuple iterator expansion) to avoid duplicate keys in the returnedRecord<string, string>. Comma-joins all headers includingSet-Cookie, consistent withget().src/test/unit/headers.spec.ts— new test file:12 test cases covering:
getSetCookie()— empty, single, multiple, comma-in-Expires fieldget("set-cookie")— backward-compatible comma-joined stringtoTuples()— separate tuples per Set-Cookie valuetoObject()— comma-join (lossy but consistent withRecord<string, string>)new Headers(existingHeaders)— preserves individual Set-Cookie valueskeys()/forEach()— one entry per Set-Cookie valuesrc/test/run-with-local-server.ts— auto-discoversunit/*.spec.tsalongside existinghttp/*.spec.ts.Backward Compatibility
get("set-cookie")"a=1, b=2""a=1, b=2"(unchanged)getSetCookie()["a=1", "b=2"]toTuples()for Set-Cookie["set-cookie", "a=1, b=2"]["set-cookie", "a=1"], ["set-cookie", "b=2"]toObject()for Set-Cookie"a=1, b=2""a=1, b=2"(unchanged)get("X-Test")multi-value"alpha, beta""alpha, beta"(unchanged)get()remains comma-joined for all headers includingset-cookie, matching the WHATWG spec's acknowledged legacy behavior.getSetCookie()is the authoritative accessor.Verification