Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Provide access to original http headers (not lowercased) #4844

Closed
stiang opened this issue Feb 25, 2013 · 16 comments
Closed

Provide access to original http headers (not lowercased) #4844

stiang opened this issue Feb 25, 2013 · 16 comments
Labels
Milestone

Comments

@stiang
Copy link

stiang commented Feb 25, 2013

Opening a new issue as requested in #1954 (comment).

It is sometimes necessary to have access to the raw http headers, before they have been lowercased. A real-world use-case is a proxy service that provides web access to headers and bodies sent over the wire, typically used when debugging/testing APIs.

Header case can matter when dealing with buggy clients or upstream servers, so for such a service to be as useful as possible it needs to display the original headers.

The solution proposed is to keep req/resp.headers lowercased, like today, but add an additional object/string, like req.rawHeaders, for those who need it.

@newtondev
Copy link

Hi there,

If I understand you correct, you only want the raw headers on the incoming request right?

@danmilon
Copy link

danmilon commented Mar 4, 2013

outgoing request headers dont get lowercased so there is no separation between raw and "normalized" headers in that case.

@danmilon
Copy link

danmilon commented Mar 4, 2013

I haven't checked with master, but that doesnt happen with v0.8. See this test and this discussion.
Link to the code?

@newtondev
Copy link

Indeed, I see the outgoing header names are not lowercased.

@newtondev
Copy link

@stiang I have added functionality that would allow you to use the mixed case form of your http header keys. Please see: newtondev/node@ddc0070

Is this the kind of functionality you were looking for? I hope someone would find it useful.

@skenqbx
Copy link

skenqbx commented Apr 22, 2013

FYI: The HTTP/1.1 spec states "Field names are case-insensitive." (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html)

@stiang
Copy link
Author

stiang commented Apr 22, 2013

@newtondev Sorry for the late reply, I got sidetracked and completely forgot about this. As far as I can tell your code looks like it would solve my issue, but according to @isaacs there is little interest in changing req.headers, only in providing access to raw headers in addition to the lowercased headers. So your patch might not get approved.

@skenqbx Yes, node.js handles headers correctly according to the spec, but that’s not the issue. Some buggy systems incorrectly treat headers with different case differently, and it is sometimes useful to retain the original "casing" (is there a word for that?) when building systems which interact with such buggy systems - especially for a proxy service like the one I described in the issue, which is designed presicely to debug HTTP protocol issues.

@diversario
Copy link

+1 about buggy clients. I would like to have access to original header names as well.

@grudzien
Copy link

I am super interested in this feature. I am running node as a proxy in front of some legacy applications and my developers didn't follow the spec so they depend on having the headers keep their case. I have gotten some of the applications fixed but it is a tiring exercise. I am happy to help implement this if it isn't already being worked on. Please let me know.

@trevnorris
Copy link

I'm currently working on changing how http headera are processed for
performance reasons. I'll keep this in mind while doing so.

This is for master, and won't be back ported to v0.10. I'm not sure a PR
would be accepted on stable (@isaacs?).

@grudzien
Copy link

All I need is for the unaltered headers to be accessible in another variable and I am happy. I can wait for your updates if this is something that has the chance of making it in. I would rather not maintain my own code. If you decide not to add this I would be happy to work on a patch.

@newtondev
Copy link

Please see my fork for the fix for this issue: https://github.com/newtondev/node

Please see the notes for the last commit that explains how to obtain the raw headers. Hope this helps you :)

Here is the diff and notes: newtondev/node@ddc0070

@grudzien
Copy link

newtondev, this will do what I need. I'd still like to see it in the main master branch. :)

@newtondev
Copy link

@grudzien thanks, I would also like to see it in the main master branch, unfortunately there is only a few people interested in the functionality. The reason being is that all headers should be lowercased and is the standard, this is just a workaround for servers that do not conform to the standard.

@isaacs
Copy link

isaacs commented Jul 17, 2013

This will not be done in stable. It is an option for master. A global switch on the http module is not a good api for this, though. We ought to just stash the raw header values on a separate key. It's not that much data.

@grudzien
Copy link

I am good with having the raw headers available and it would be nice if I could substitute them in my proxy code so that my users only see them. This will ensure that my legacy apps will function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants