Closed
Description
Code first:
fetch( url, {
headers:{
'Cookie':'some key-value pass to server',
'User-Agent': 'react-native Android'
}
);
I found that the name of headers has been converted to lower case by normalizeName .
And when I use it on React-Native (Android platform) , it send a HTTP request with lower case header name which not be recognized in our Server.
There is the row HTTP text I've capture:
GET http://... HTTP/1.1
cookie: ...
user-agent: react-native Android
So. Why should we do toLowerCase to header name ?
Activity
dgraham commentedon Dec 18, 2015
HTTP headers are case insensitive. The lowercase header names were added in #85.
mc-zone commentedon Dec 18, 2015
@dgraham. Thx for explanation!
smith commentedon Jun 14, 2016
I believe the native fetch implementation (in Chrome/Mac 51.0.2704.84 (64-bit) for me) also downcases the header names.
amrdraz commentedon Jul 16, 2016
While Http headers should be case-insensitive, a server for a client we're dealing with has miss implemented the spec. They check authorization header using equality it seems and accordingly produce an error.
We do not have control over modifying the code of that server, we can submit a request but that will take time to process.
If according to the spec the header should be case-insensitive I don't see why forcing the headers to be lower case matters then, we should be generally allowed to send headers in any case form.
hashplus commentedon Oct 31, 2016
chrome-dev-tool Network panel will divide these requests into Other not XHR.
kobvel commentedon Oct 31, 2016
So, no way to prevent Lowercasing of headers?
mislav commentedon Oct 31, 2016
@kobvel That's correct.
staabm commentedon Oct 31, 2016
@hashplus you should report that bug to the chrome team.
normalizeName
lowercasing case-sensitive header keys #478AMorgaut commentedon Mar 7, 2017
Same issue when sending requests to Gerrit server
It doesn't work when header 'X-Gerrit-Auth' is transformed to 'x-gerrit-auth' by the fetch API
I can post an issue to the Gerrit team but...
I'm pretty sure that plenty of legacy servers will have similar issues
(even more on custom header names that are not managed by core http server code but by application level one)
AMorgaut commentedon Mar 8, 2017
To get an idea, I looked into Gerrit Server implementation
It is based on Tomcat which getHeader() API is case insensitive
This header is occasionally added to the CORS
Access-Control-Request-Headers
HTTP header.To handle CORS, they use a filter written this way
.filter(h -> !ALLOWED_CORS_REQUEST_HEADERS.contains(h))
and of course, they didn't lowercased their header values before.I created a ticket to the gerrit project: https://bugs.chromium.org/p/gerrit/issues/detail?id=5733
My point is just that we can be sure that the fetch API is probably unfortunately not usable, as is, on many (how many?) legacy servers.
It may be ok on Open Source project based services, as the mentioned one, to which we can contribute, but it can be a way harder issue when connecting to commercial closed-source services (or open source based ones that are not regularly maintained)
amrdraz commentedon Mar 8, 2017
@AMorgaut the workaround I resorted to was using axios until the server I was working with fixed their problem.
since it's fetch that lower cases not the XHR Object
this.normalizedRequestAttrs()
with form-data is case-dependent miragejs/ember-cli-mirage#1398iamawaisakram commentedon Feb 18, 2019
It's not working now! Even the headers in axios are converted to lowercase now.
MiriDevAndro commentedon Mar 31, 2020
omg i want to use header as case sensitive any help . i have use and flutter but same as react native . just java is perfect.
msvargas commentedon Sep 30, 2020
This working in react-native, I share here to help anybody.
polyfill.ts
index.js
Ross-Hale commentedon Sep 30, 2020
Scripts for Artificial Intelligence
Ross-Hale commentedon Sep 30, 2020
We need Artificial Intelligence since Natural Intelligence is in such short supply!