I'm writing an HTTP API library for use in Atom Electron. It is based on fetch
. The server is outside of my control, but is written in PHP and I can see it checks headers in a case-sensitive fashion.
My code is something like:
const headers = new Headers(); headers.append('Authorization', `Bearer ${key}`); const init = { method: 'GET', headers: headers } const req = new Request(baseUrl + '/items?format=json'); return fetch(req, init);
The request is rejected with a 403 FORBIDDEN
error. When I look at the request in the Electron Newtork panel, the request headers are present but Authorization
has become authorization
.
I know fetch()
is just following the HTTP Standard, but is there a simple way to get fetch()
to send the headers as I supply them?
Currently fetch will toLowercase()
all headers. (there is some discussion here https://github.com/whatwg/fetch/issues/304 about optional disabling).
For now you may need to use http://api.jquery.com/jquery.ajax/ with the header
option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With