-
Notifications
You must be signed in to change notification settings - Fork 47
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 #33
Comments
Migrated from sinonjs/sinon#607 (comment) @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? |
Migrated from sinonjs/sinon#607 (comment) 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.) |
Migrated from sinonjs/sinon#607 (comment)
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 |
Migrated from sinonjs/sinon#607 (comment) This is still the case as of Sinon v1.17.2. |
Migrated from sinonjs/sinon#607 (comment) Just experienced this, too, when using Sinon and its XHR mock on Node. It also lacks the |
Thank you! |
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've not tried, but I assume this issue would've been closed earlier if it were fixed. |
Migrated from sinonjs/sinon#607
Originally created by @terinjokes on Thu, 20 Nov 2014 00:47:58 GMT
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: