"proxyError" event emitted twice
Created by: subnetmarco
I created a simple proxy server that tries to proxy the request to a non existent server. I've written this to return an error message when the final host is unreachable.
After I make the request, when the proxyError
is caught, I keep getting two times the same error:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
I'm expecting the error to be thrown only once. This is the code I'm using:
var httpProxy = require('http-proxy');
var server = httpProxy.createServer(function (req, res, proxy) {
var buffer = httpProxy.buffer(req);
proxy.proxyRequest(req, res, {
host: '127.0.0.1',
port: 10000,
buffer: buffer
});
});
server.proxy.on('proxyError', function (err, req, res) {
// This error is printed two times!
console.log(err);
});
server.proxy.on('end', function() {
console.log("The request was proxied.");
});
server.listen(9000);
Assuming that nothing is running on 127.0.0.1:10000
, trying to execute:
curl http://127.0.0.1:9000
prints two times the same error message to the console.
I'm running:
- node v0.8.17
- node-http-proxy v0.8.7