Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Changing the case of proxied headers breaks poorly written clients #40

timmattison opened this Issue Apr 26, 2011 · 7 comments


None yet
5 participants

timmattison commented Apr 26, 2011

I am working with a system that is very sensitive, against the standards, to the case of headers that are passed back to it. The current code in node-http-proxy takes all of the headers (ie. "Content-Type") and converts them to lower case. I know that the client is behaving badly here but it would be nice to have this configurable. I will see if I can code this up and send a pull request.

In the meantime, is there a way to disable this behavior?


indexzero commented Apr 26, 2011

I believe that this is the behavior of node.js core itself, so probably not.


timmattison commented Apr 26, 2011

Bummer. Can I intercept the responses before the client sees them and "fix" them by hand or are you saying that even if I do that that node.js will do what it wants?


indexzero commented Apr 26, 2011

I would post to the node.js list about this. I'm not entirely sure. I've never encountered a case-sensitive HTTP parser.

@indexzero indexzero closed this Apr 26, 2011

d11wtq commented Aug 15, 2012

I did this to make the headers more aesthetically pleasing. I agree it's unnecessary though.

function normalizeResponse(res) {
  var writeHead = res.writeHead;
  res.writeHead = function(status, headers) {
    cleaned = {};
    for (var k in headers) {
      cleaned[k.replace(/^[a-z]|-[a-z]/g, function(a){return a.toUpperCase()})] = headers[k];
    writeHead.call(this, status, cleaned);

Then I just apply the monkey patch inline:

http.createServer(function(req, res) {
  router.proxyRequest(req, res);

I'm pretty sure the original header names are available in the response though, to do this without the gsub. I'll have a look.

Is there a way to 'fix' headers on a proxyReq event? I have the same problem where the server I am connecting to cares about the case sensitivity of the headers so need to correct node's tampering.

@d11wtq did you ever find out where the original header names were store? It would be good if I could get node-http-proxy to forward the original case-preserved headers rather than it using the lower-cased versions from node.

For anyone who comes across this thread as I did, I created a fork that forwards on the raw headers to the target rather than the ones that node has modified.


mixxen commented Dec 13, 2016

djskinners modification should be applied when preserveHeaderKeyCase is set to true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment