-
Notifications
You must be signed in to change notification settings - Fork 135
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
Explicitly set contentType in Firefox's Request #1165
Conversation
The default value is `"application/x-www-form-urlencoded"`, but we usually want JSON. In some versions of Firefox, passing `{headers: {"Content-Type": "application/json"}` to the Request constructor works. However in other versions, such as the latest Developer Edition 51.0a2, the actual header sent erroneously becomes `Content-Type: application/x-www-form-urlencoded, application/json`. This breaks XCloud and might break other services as well. This patch simply ensures that if we ask for `application/json`, we get `application/json`.
Sorry, but, just so I'm clear, the actually issue here is that setting the content type through the headers of Firefox XHR requests breaks in FF 51? Isn't that a regression that should be reported to Mozilla then? Or am I misunderstanding? |
It's not XHR that's changed, it's the internal request API for addons, which XKit uses because it's not subject to origin restrictions. A Request has a It might in fact be a regression however, since I can't see in Bugzilla or the commit history why the change was made. |
We should probably confirm that this is at least a intended change before On Fri, Sep 30, 2016 at 3:11 AM Danielle McLean notifications@github.com
|
especially since creating a new extension version and getting everybody On Fri, Sep 30, 2016 at 3:11 AM Danielle McLean notifications@github.com
|
This behavior conforms with the XMLHttpRequest standard's specification of setRequestHeader, specifically the duplicate usage case. Based on how request.js functions this is also the correct fix to perform. |
@hobinjk Not sure I follow. Here's the relevant language:
and
emphasis mine. where does this say they should prepend a default content type if we set one explicitly in our headers? (there's another paragraph here that looks relevant, but a close reading indicates that its actually about charsets and encodings, which we're not really messing with) |
@nightpool The problem is that the Request library does setRequestHeader(request.contentType) regardless of whether Content-Type is specified in headers. It has done this since at least 2015 although the fact that Content-Type must be specified using contentType is not documented anywhere. |
@hobinjk I'm down to approve this change for now, but i'm still confused about how this is not a regression, from a user-facing point of view |
@nightpool Yeah, it's definitely unfortunate that this is necessary. It might be worthwhile to file a bug on bugzilla to try to point out the unexpected behavior,. @00dani Thanks for the PR! I'll try to get an extension update going tomorrow @homu r+ |
📌 Commit 0056dcd has been approved by |
Explicitly set contentType in Firefox's Request The default value is `"application/x-www-form-urlencoded"`, but we usually want JSON. In some versions of Firefox, passing `{headers: {"Content-Type": "application/json"}}` to the Request constructor works. However in other versions, such as the latest Developer Edition 51.0a2, the actual header sent erroneously becomes `Content-Type: application/x-www-form-urlencoded, application/json`. This breaks XCloud and might break other services as well. This patch simply ensures that if we ask for `application/json`, we get `application/json`.
☀️ Test successful - status |
The default value is
"application/x-www-form-urlencoded"
, but we usually want JSON. In some versions of Firefox, passing{headers: {"Content-Type": "application/json"}}
to the Request constructor works. However in other versions, such as the latest Developer Edition 51.0a2, the actual header sent erroneously becomesContent-Type: application/x-www-form-urlencoded, application/json
. This breaks XCloud and might break other services as well.This patch simply ensures that if we ask for
application/json
, we getapplication/json
.