Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetch() sends lower case header keys

Tags:

javascript

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?

like image 709
will-hart Avatar asked Jan 07 '16 13:01

will-hart


1 Answers

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.

like image 160
paddycorr Avatar answered Oct 20 '22 01:10

paddycorr