Search code examples
node.jsproxyhttp-headersnode-http-proxy

Node http-proxy - HTTP message contains illegal headers


Using node http-proxy module, I have no issues when proxying to a host with GET. But when I use POST and proxy to the same host, I get Status Code:400 Bad Request with HTTP message contains illegal headers.

I checked out the proxyReq headers and they look good, the same exact headers used on successful gets.

  _headers: 
   { 'x-forwarded-proto': 'http',
     'x-forwarded-port': '9000',
     'x-forwarded-for': '::ffff:10.3.117.47',
     'accept-language': 'en-US,en;q=0.8',
     'accept-encoding': 'gzip,deflate,sdch',
     'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36',
     accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
     'cache-control': 'no-cache',
     pragma: 'no-cache',
     connection: 'close',
     host: '10.1.1.1:9000',
     'x-auth-token': 'tokenStuff' 
}

On a side note, if I make the same api call out directly to the proxied host without using the proxy, I don't get this message. Same post and json payload and headers


Solution

  • Answer: It was the http-proxy option xfwd: true that was causing this.