You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
Issue details
When using the HttpLink provided by Apollo in combination with the https://www.npmjs.com/package/xmlhttprequest XMLHttpRequest polyfill, the request's content header will be set to text/plain rather than application/json.
This is caused partially due to how Apollo sets request headers and partially how the xmlhttprequest polyfill handles the content-type header; The polyfill only checks for Content-Type (note the capitalization), whereas Apollo sets content-type. In the case the polyfill doesn't find the header with that capitalization, it overwrites it with text/plain.
Overall it's a silly issue, and I'd lean on it being more the fault of the polyfill (due to how in the spec headers are described as case-insensitive), however Apollo also prevents me from overwriting the capitalization of the header in the HttpLink options, even though I can use it to set other headers.
Regardless, I thought I would share my issue and the cause of it in case someone else happens to hit the same problem. e.g. when setting up jest with their react native / expo setup, which is when I hit the problem.
Apollo should probably allow for the overwriting of the content type header, as has been suggested elsewhere (apollographql/apollo-fetch#39).
Seems like the oldest issue in the offending polyfill about this is 8 years old by now 😄. I think we can assume it's not going to get addressed on that side at the very least: driverdan/node-XMLHttpRequest#20
Really the takeaway here is to not use the polyfills in question, and opt-in for node-fetch instead for example. Using node-fetch fitched my issue at least.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Issue details
When using the HttpLink provided by Apollo in combination with the https://www.npmjs.com/package/xmlhttprequest XMLHttpRequest polyfill, the request's content header will be set to
text/plain
rather thanapplication/json
.This is caused partially due to how Apollo sets request headers and partially how the xmlhttprequest polyfill handles the content-type header; The polyfill only checks for
Content-Type
(note the capitalization), whereas Apollo setscontent-type
. In the case the polyfill doesn't find the header with that capitalization, it overwrites it withtext/plain
.Relevant issue on the polyfills page: driverdan/node-XMLHttpRequest#183
Overall it's a silly issue, and I'd lean on it being more the fault of the polyfill (due to how in the spec headers are described as case-insensitive), however Apollo also prevents me from overwriting the capitalization of the header in the HttpLink options, even though I can use it to set other headers.
Regardless, I thought I would share my issue and the cause of it in case someone else happens to hit the same problem. e.g. when setting up jest with their react native / expo setup, which is when I hit the problem.
Apollo should probably allow for the overwriting of the content type header, as has been suggested elsewhere (apollographql/apollo-fetch#39).
A simple reproduction
(jest) setup:
link:
Then perform any query, and the
Content-Type
header will be set totext/plain
The text was updated successfully, but these errors were encountered: