node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

Preserve header case for incoming requests.

Open mixxen opened this issue 8 years ago • 8 comments

#1107

mixxen avatar Dec 13 '16 10:12 mixxen

I'm welcome this PR, because I didn't care about incoming request. But I'm not a maintainer, please take their review ;)

IMO, Existing specs seems not to cover additional behavior. Would you please add specs?

pachirel avatar Dec 16 '16 14:12 pachirel

I think we've just bumped into some problems related to this. Is there a way we can help to get this merged and released?

honzajavorek avatar Apr 27 '17 15:04 honzajavorek

It's worth to mention that the http message spec describes headers as a case insensitive. Therefore clients/servers that relays on headers cases sensitivity are not complying with the spec and should not be expected to work properly. Developers shouldn't get used to bad practices (especially if something is against the spec) and therefore this PR shouldn't be accepted. That's only my opinion.

jarrodek avatar Jul 14 '17 15:07 jarrodek

@jarrodek The issue here is dealing with 3rd party software or legacy software that does not adhere to the spec and we have no control over.

mixxen avatar Jul 14 '17 21:07 mixxen

The same with us. I think node-http-proxy preserving case of header names would be something similar to "be benevolent in what you accept and strict about what you produce". I totally agree it's ridiculous some software is HTTP header name case-sensitive, but software is made by humans and humans make mistakes.

This is very simple change node-http-proxy can do and it even actually makes sort of sense - IMHO the proxy should pass things "as is" to be as unnoticeable as possible, unless it really needs to touch them and modify them for some purpose.

honzajavorek avatar Jul 15 '17 10:07 honzajavorek

I totally agree with @honzajavorek The proxy should be totally transparent for passing data and not alter them. In this case, however, it doesn't actually changes the data. If anything, that's the problem of Node's Request object and not the proxy. This PR actually introduce a behavior where data are altered by the proxy. This PR should be sent to Node because that's the source of the problem and not this module.

jarrodek avatar Jul 15 '17 21:07 jarrodek

Just ran into this problem where for whatever reason the service I'm calling expects a header to be Mixed Case ('X-HTTP-Method-Override'). Even with the preserveHeaderKeyCase: true it looks like the header is being rewritten to ('x-http-method-override'). I'm able to work around this by rewriting the headers... but it's a pretty lame solution since I'd have to do it for each header and I may not now what the original case was. Why wouldn't it just leave the header casing alone in the first place??

const onProxyReq = (proxyReq, req) => {
  if (req.headers['x-http-method-override']) {
    proxyReq.setHeader('X-HTTP-Method-Override', req.headers['x-http-method-override']);
  }
};

mrichmond avatar Sep 13 '18 16:09 mrichmond

Just ran into this same issue as @mrichmond described... Why are headers rewritten to lower-case?

ItsEcholot avatar Sep 08 '21 09:09 ItsEcholot