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.
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:
const xmlhttprequestPolyfill = require("xmlhttprequest");
const fetchPolifill = require("whatwg-fetch");
global.XMLHttpRequest = xmlhttprequestPolyfill.XMLHttpRequest;
global.fetch = fetchPolifill.fetch;
global.Request = fetchPolifill.Request;
global.Headers = fetchPolifill.Headers;
global.Response = fetchPolifill.Respons;
link:
const link = ApolloLink.from([
new HttpLink({
uri: GQL_ENDPOINT,
credentials: "same-origin"
})
]);
Then perform any query, and the Content-Type header will be set to text/plain
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/plainrather 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-Typeheader will be set totext/plain