-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
XHR: Content-Type clobbered #607
Comments
@terinjokes Thank you for reporting this.
Does this behaviour differ from what out-in-the-wild implementations of XMLHttpRequest? Do they all behave the same way?
By real, do you mean IE10 and onwards? ;) IE9 and below doesn't have the Do you have a proposal on how to improve FakeXMLHttpRequest to match developers' expectations, without getting to close to one specific real-world implementation? |
Just now I've tested the behavior of the following browsers, which were at my easy disposal: IE9, IE10, Chrome 39, Firefox 34, and Safari 8. I created a new XHR object, and set the "Content-Type" header: var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://httpbin.org/headers', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
if (this.readyState==4 || this.readyState=="complete") {
console.log(this.responseText);
}
}
xhr.send() In every case, the response body shows that the browser sent the request with "Content-Type" set to "application/json".
That's fine. IE8 doesn't support |
Just experienced this, too, when using Sinon and its XHR mock on Node. It also lacks the |
Not sure why this was marked as a feature request. This is clearly a bug, as @terinjokes's example shows. This requires ";charset=utf-8" to be appended to all tests that check the sent Content-Type header. (Even "text/plain" shouldn't have a charset appended if it wasn't set explicitly in the XHR.) |
This is still the case as of Sinon v1.17.2. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I suspect that is still the case 2 years later unless someone can confirm it's definitely not. |
Let's investigate this further |
@mroderick should this move to the nise tracker? |
@mnahkies, preferably, yes. If you would do the honours it saves us the trouble :-) Please refer to this bug to keep a history. |
@mnahkies that would be great, thank you! I've used this with success in the past: https://github.com/buildo/gh-issue-mover |
Issue migrated to sinonjs/nise#33 |
Closed in favor of the |
FakeXMLHttpRequest's
send
method currently clobbers the "Content-Type" header if set, by removing anything after the first ";" and forcibly appending ";charset=utf-8".A real XHR object allows sending binary data via
TypedArray
s,ArrayBuffer
s, andBlob
s. They also correctly form encode when sent withFormData
values. As "Content-Type" might have application-specific behavior, blindingly clobbering them makes it difficult for developers to properly test the functionality.The text was updated successfully, but these errors were encountered: