Created by: samalba
In some cases, when there is an error, the headers are sent twice which throws an exception. I was able to reproduce by doing this:
$ nc localhost 1080 << EOF
> GET / HTTP/1.1
> Host: foobar
>
> EOF
`foobar' is a valid proxied website. A proxy using node-http-proxy is running on localhost:1080.
This produces the following error:
http.js:708
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:708:11)
at /Users/shad/Dropbox/work/hipache/node_modules/http-proxy/lib/node-http-proxy/http-proxy.js:332:13
at Array.forEach (native)
at ClientRequest.<anonymous> (/Users/shad/Dropbox/work/hipache/node_modules/http-proxy/lib/node-http-proxy/http-proxy.js:328:35)
at ClientRequest.g (events.js:175:14)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1630:21)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:119:23)
at Socket.socketOnData [as ondata] (http.js:1528:20)
at TCP.onread (net.js:495:27)
The problem here is that netcat does not read anything. I tried with a script that reads the response and the error does not occur. The simple `if' statement I added prevents the bug to happen and everything then works normally.