question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Headers all lowercased

See original GitHub issue

Been trying to debug an issue I’ve been having where the API I’m calling is returning a 500 error. Traced this down to this package. The server is expecting Content-Type in Title-Case.

Node-fetch seems to lowercase all headers and that’s what it sends to the server on the way out.

Looking into #260 it shouldn’t be this way, as the fetch spec seemed to have been changed to insist on the headers remaining untouched (Which would be expected), however that issue was closed citing it’s a nodeJS issue… but the code in node-fetch is doing the toLowerCase() call.

In my opinion and experience, if I set Content-Type in my options, it should remain untouched and go through to the server like that.

Is there a work-around for now, or still waiting for a fix?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
adam-nielsencommented, Apr 12, 2022

For anyone else struggling with this issue, I have come up with a workaround:

// Save the original .toLowerCase() function.
const originalLowerCase = String.prototype.toLowerCase;
// Replace it with a no-op.
String.prototype.toLowerCase = function() { return this; };
// Call fetch() as normal but return immediately.
const pFetch = fetch(...);
// Restore the original function, so it's available for other code to use while we are waiting.
String.prototype.toLowerCase = originalLowerCase;
// Wait for the fetch() to complete.
const response = await pFetch;

There are probably a ton of situations where this will break code in weird ways, but for simple requests, it does the job. Hopefully node-fetch will be fixed so dodgy hacks like this are no longer necessary when trying to communicate with legacy devices!

3reactions
qwright10commented, Apr 1, 2020

According to RFC 2616, HTTP header names are case-insensitive. RFC 7540 states that HTTP2 header names must be lowercase and non-lowercase headers should be treated as malformed requests. You should raise this with the API developers since lowercase headers and case-insensitive header searches should be implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are HTTP headers case-sensitive?
officially, headers are case insensitive, however, it is common practice to capitalize the first letter of every word.
Read more >
Why do headers convert into lowercase automatically? #71
While uppercase headers can be used at the application level, they will always be sent as lowercase. However, header field names MUST be ......
Read more >
HTTP Headers are Case-Insensitive
HTTP Headers are Case-Insensitive. HTTP headers are not case-sensitive, so we are free to convert them to all-lowercase in our applications.
Read more >
HTTP client request headers (lowercase) issue
A recent update changed how client request headers are sent to force all headers to lowercase. This is causing problems with some well-established...
Read more >
HTTP/1.1 Header Casing
When handling HTTP/1.1, Envoy will normalize the header keys to be all lowercase. While this is compliant with the HTTP/1.1 spec, in practice...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found