hostname router proxy throw "Can't render headers after they are sent to the client" #405

Closed
bfx81 opened this Issue Apr 17, 2013 · 4 comments

Projects

None yet

4 participants

@bfx81

http-proxy@0.10.1 (even with 0.10.0) nodejs@0.10.4 (even with 0.10.3)
Ubuntu 12.10 64bit

"use strict";
var httpProxy = require('http-proxy'),
    http = require('http');

var options = {
  hostnameOnly : true,
  router : {
    'local.test.it' : '127.0.0.1:9000',
    'api.test.it' : '127.0.0.1:8080'
  }
}
var server = httpProxy.createServer(options);
server.listen(80);
http.js:734
    throw new Error('Can\'t render headers after they are sent to the client.'
          ^
Error: Can't render headers after they are sent to the client.
    at ServerResponse.OutgoingMessage._renderHeaders (http.js:734:11)
    at ServerResponse.writeHead (http.js:1098:20)
    at ClientRequest.proxyError (/home/bluefox/Projects/dev-biz/gustaff/web/node_modules/http-proxy/lib/node-http-proxy/http-proxy.js:203:9)
    at ClientRequest.g (events.js:175:14)
    at ClientRequest.EventEmitter.emit (events.js:95:17)
    at Socket.socketOnData (http.js:1528:9)
    at TCP.onread (net.js:510:27)

There's a tomcat server on localhost:8080 and a nodejs "grunt server" on localhost:9000.
The exception is thrown VERY frequently (it's a 99% ALWAYS) after involving authentication on the tomcat server.
The autentication is obtained with a quite standard session cookie with the following workflow:

  • api.test.it/auth/login --> redirect to an OAuth provider
  • OAuth provider --> redirect to api.test.it/auth/result (this page validate the user and return a session)

The app itself on tomcat allow CORS calls exchange.
Any idea? Tnx in advance

@bwaters

I am getting this same error with http-proxy@0.10.2 on node 0.8.24 my dump looks like the following. Not sure what types of requests are triggering it.

http.js:673
throw new Error('Can\'t set headers after they are sent.');
^
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:673:11)
at HttpProxy.proxyRequest (/usr/local/share/adproxy/node_modules/http-proxy/lib/node-http-proxy/http-proxy.js:330:11)
at Array.forEach (native)
at ClientRequest. (/usr/local/share/adproxy/node_modules/http-proxy/lib/node-http-proxy/http-proxy.js:329:35)
at ClientRequest.g (events.js:192:14)
at ClientRequest.EventEmitter.emit (events.js:96:17)
at HTTPParser.parserOnIncomingClient as onIncoming
at HTTPParser.parserOnHeadersComplete as onHeadersComplete
at Socket.socketOnData as ondata
at TCP.onread (net.js:404:27)

@bwaters

Looks like same as #388 Also has a code fix waiting for a pull request

@LoganBarnett

Ran into this situation where I was bouncing back the Origin header as Access-Control-Allow-Origin to address CORS behavior. There's some circumstances where the Origin header isn't set and it was causing undefined to be passed as the header value, causing this error. Making sure we at least passed an empty string worked around this issue.

@jcrugzz
nodejitsu member

This is an old issue that is no longer relevant to the current version of http-proxy

@jcrugzz jcrugzz closed this Oct 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment