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.

HTTP Header with case-insensitive header names

See original GitHub issue

Hi, i’ve discovered another minor issue.

Describe the bug define content-type: text/html as response header results in duplicate content type header: grafik

To Reproduce create a route that returns a html response like

  return ({
      headers: {
          ...filterProxyRequestHeaders(response.headers),
          "content-type": "text/html"
      },
      body: bodyStream
  });

Expected behavior response contains only "content-type": "text/html" as content type header.

Desktop (please complete the following information):

  • OS => MacOS BigSur
  • Package + Version
   "@marblejs/core": "^3.4.8",
   "@marblejs/middleware-body": "^3.4.8",
   "@marblejs/middleware-logger": "^3.4.8",
  • Node version => v14.12.0

Additional context i found this one as a short explainer that the headers in http protocol are case-insensitive: https://stackoverflow.com/a/5259004

My use case for a bit more context: I use undici a nodejs http client: https://github.com/nodejs/undici All response headers are in lower case letters and my plan is to forward them, as my marble server acts like a proxy in this case.

Workaround For now i can map the content-type header to the upper case one. But this can be tedious process if more headers are affected.

Let me know if i can help with that if you want to improve this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
DawidYerginyancommented, Jan 26, 2021

Even tho It is technically a bugfix and a non breaking change according to the HTTP Spec I’d opt to introduce it gradually for the ☝🏻 mentioned reasons with service2service communication and test cases. I propose to patch the behavior change under a feature-toggle disabled by default with a sufficient warning linking to the issue, stating that It is going to be the default behavior in the X upcoming version and introduce it as a breaking change in the next minor/major.

One option would be to control it with an env variable, something like

MARBLE_HTTP_CASE_INSENSITIVE_HEADER_NAMES=true

Considering that the change affects only the HTTP server, It could also be a temporary optional server factory parameter

import { createServer } from '@marblejs/core';

const httpServer = createServer({
  port,
  listener,
  dependencies,
  options: {
    httpsOptions,
    caseInsensitiveHeaderNames: true,
  },
});
2reactions
alexanderbartelscommented, Feb 4, 2021

sorry for the late response - its a bit crazy at work currently. @JozefFlakus if you haven’t started yet, i can have a look at this in the upcoming weekend.

I like the idea from @DawidYerginyan to use a feature flag. I think an env variable would be a proper choice. With this solution the code must not be touched twice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are HTTP headers case-sensitive? - Stack Overflow
HTTP header names are case-insensitive, according to RFC 2616: 4.2: Each header field consists of a name followed by a colon (":") and...
Read more >
HTTP Headers are Case-Insensitive | Beamtic
While header names are case insensitive according to the HTTP specification, there is little reason to normalize the capitalization of header ...
Read more >
Are http headers case sensitive? - My Programming Notes
Are http headers case-insensitive? The http header names are case-insensitive. So “Content-Type” is equivalent with “content-type”. Are http ...
Read more >
HTTP/2 Header Casing - Yaakov's Blog
HTTP header names have been case-insensitive since 1999. If you have code anywhere that cares about case sensitivity of HTTP headers, go fix...
Read more >
Case insensitive in http headers. #11104 - netty/netty - GitHub
Standard says headers are not case sensitive, so I would rather not rely on that. https://tools.ietf.org/html/rfc2616#page-31. 4.2 Message ...
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