-
-
Notifications
You must be signed in to change notification settings - Fork 36
fix(node-fetch): reading Headers.get('set-cookie') when _map has not been initialised
#2074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…not been initialised
Reading `Headers.get('set-cookie')` gives the initial value (empty array) until `getMap` is called
This PR fixes the bug
WalkthroughThe pull request refines the internal control flow in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant PonyfillHeaders
Client->>PonyfillHeaders: Call _get("set-cookie")
PonyfillHeaders->>PonyfillHeaders: Check if _map is initialized
alt _map is not initialized
PonyfillHeaders->>PonyfillHeaders: Initialize _map
else _map is already initialized
PonyfillHeaders->>PonyfillHeaders: Use existing _map
end
PonyfillHeaders-->>Client: Return 'set-cookie' values
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (8)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/node-fetch/src/Headers.ts (1)
22-23: LGTM! Fix ensures consistent behavior for 'set-cookie' headers.The changes correctly ensure that
_setCookiesis populated by initializing_mapwhen needed, fixing the bug whereHeaders.get('set-cookie')would return an empty result.Add tests to verify the fix.
Consider adding tests to verify the behavior of
Headers.get('set-cookie')before and after other operations that would initialize_map.Would you like me to help generate test cases that cover this scenario?
Description
Reading
Headers.get('set-cookie')gives the initial value (empty array) untilgetMapis calledThis PR fixes the bug
Related #2076
Type of change
How Has This Been Tested?
Tested the code snippet in a local fork with reproduction mentioned in the issue ticket.
Test Environment:
@whatwg-node/node-fetch: 0.7.9Checklist:
CONTRIBUTING doc and the
style guidelines of this project
Additional Context
Although it might seem that generating
_mapis overkill for reading the set-cookie header, if you look at the implementation ofgetMapyou'll realise that_setCookieis populated by traversing the entire headers list, which is effectively whatgetMapdoes, so this seems to be the best solution without changing theHeadersobject significantly.Summary by CodeRabbit
Summary by CodeRabbit