Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Request): URLSearchParams body w/ Headers obj #1410

Merged
merged 1 commit into from May 4, 2022

Conversation

KhafraDev
Copy link
Member

Fixes #1407

Although the spec says to "append" the header, setting it should make no difference as the check beforehand ensures that no 'content-type' header exists.

p.s.: I have no idea how the header was being duplicated 馃槙

@codecov-commenter
Copy link

codecov-commenter commented May 3, 2022

Codecov Report

Merging #1410 (0babdb1) into main (3ec5a8e) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1410   +/-   ##
=======================================
  Coverage   94.28%   94.28%           
=======================================
  Files          47       47           
  Lines        4250     4250           
=======================================
  Hits         4007     4007           
  Misses        243      243           
Impacted Files Coverage 螖
lib/fetch/request.js 85.65% <100.00%> (酶)

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 3ec5a8e...0babdb1. Read the comment docs.

this[kHeaders].append('content-type', contentType)
this[kState].headersList.append('content-type', contentType)
this[kHeaders].set('content-type', contentType)
this[kState].headersList.set('content-type', contentType)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason for the duplication is this[kHeaders][kHeadersList] === this[kState].headersList, making this second call redundant.

See

return this[kHeadersList].append(String(args[0]), String(args[1]))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too, but removing the second call caused some tests (from the node-fetch test suite) to fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think here we should use .set. If I remember correctly, the old implementation was using .set/.push as well.

Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to add those issues. The good part is that we are adding tests to these missing asserts smile

@KhafraDev
Copy link
Member Author

No problem at all, there's no way anyone would have noticed these things without tests.

I also discovered a bunch of bugs in the Headers class while working on this PR so this issue will end up making Headers more spec compliant!

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 2307137 into nodejs:main May 4, 2022
@KhafraDev KhafraDev deleted the duped-headers branch May 4, 2022 15:28
KhafraDev added a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
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.

Content type header set incorrectly (5.1.0 regression)
5 participants