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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case-insensitive check for content type before setting it #18

Merged

Conversation

YarnSaw
Copy link

@YarnSaw YarnSaw commented Oct 21, 2024

Updated tests/test-headers.js to test for the case this PR addresses.

If the following conditions were met it would result in the content-type header always being "text/plain;charset=UTF-8":

  • The method is not GET or HEAD
  • Data is being sent
  • When setting the content-type header, the key used is anything other than a case-sensitive "Content-Type"

I encountered it when sending a POST request with xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');, then was surprised by the server receiving the content-type as text/plain.

Copy link
Owner

@mjwwit mjwwit left a comment

Choose a reason for hiding this comment

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

Nice find! Thanks for adding the necessary test changes as well.

lib/XMLHttpRequest.js Outdated Show resolved Hide resolved
@mjwwit mjwwit merged commit 3651620 into mjwwit:master Oct 23, 2024
4 checks passed
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.

2 participants