Repository navigation
fix(parse): support legacy fetch headers - #93
awais-ur-rehman wants to merge 1 commit into
Conversation
|
Hi, do you have a real-world example of where this fails, or is this more of a theoretical fix? I ask because I'm fairly certain I remember this library working with fetch before the advent of |
| } else if (typeof input.headers.get === "function") { | ||
| input = input.headers.get("set-cookie"); | ||
| } else if (input.headers["set-cookie"]) { | ||
| // fast-path for node.js (which automatically normalizes header names to lower-case) | ||
| input = input.headers["set-cookie"]; |
There was a problem hiding this comment.
If we do add get() support, it should probably come after the node.js fast-path.
(getSetCookie() comes first because of some environments (mostly React Native) where it provides a pre-split array but input.headers["set-cookie"] provides a combined string that takes extra work to process.)
|
Found by code reading, not from a production report. I reproduced it with an unmodified const { Response } = require('node-fetch');
const response = new Response(null, {
headers: { 'set-cookie': 'foo=bar' }
});Here I haven't verified React Native. Browser restrictions still apply; this fallback only reads a header the fetch implementation already exposes. |
Ok, let's add a unit test like that (add node-fetch as a dev dependency), and also make the other change I suggested where |
Summary
A fetch Response whose Headers supports
get()but lacksgetSetCookie()currently produces an empty cookie list. Read its combined Set-Cookie value throughget('set-cookie')and pass it through the existing splitter; keepgetSetCookie()preferred when available. Update the input declaration to accept these Headers implementations.Breaking Changes
None.
Testing
npm testpasses build, lint, 75 Mocha tests, and tsd typecheck on Node24/macOS;git diff --checkpasses.Manual check: pass a Response-like object with
headers.get("set-cookie")returningfoo=bar;parse()now returns that cookie.AI assistance
OpenAI Codex assisted with investigation, implementation, regression tests, review, and validation.