Commit 7e61f0cf authored by Fedor Indutny's avatar Fedor Indutny

Moved error handling to response.on('end'), fixed error handling in websocket's part

parent 56003b52
......@@ -159,7 +159,9 @@ HttpProxy.prototype = {
if(req.method !== 'HEAD') {
res.write('An error has occurred: ' + sys.puts(JSON.stringify(err)));
}
// Response end may never come so removeListener here
reverse_proxy.removeListener('error', error);
res.end();
};
......@@ -195,6 +197,7 @@ HttpProxy.prototype = {
response.addListener('end', function () {
// Remark: Emit the end event for testability
self.emitter.emit('proxy', null, self.body);
reverse_proxy.removeListener('error', error);
res.end();
});
});
......@@ -207,7 +210,6 @@ HttpProxy.prototype = {
// At the end of the client request, we are going to stop the proxied request
req.addListener('end', function () {
reverse_proxy.end();
reverse_proxy.removeListener('error', error);
});
self.unwatch(req);
......@@ -276,8 +278,6 @@ HttpProxy.prototype = {
var request = client.request('GET', req.url, headers);
var errorListener = function (error) {
p.emit('error', error);
request.emit('error', error);
socket.end();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment