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
...@@ -160,6 +160,8 @@ HttpProxy.prototype = { ...@@ -160,6 +160,8 @@ HttpProxy.prototype = {
res.write('An error has occurred: ' + sys.puts(JSON.stringify(err))); 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(); res.end();
}; };
...@@ -195,6 +197,7 @@ HttpProxy.prototype = { ...@@ -195,6 +197,7 @@ HttpProxy.prototype = {
response.addListener('end', function () { response.addListener('end', function () {
// Remark: Emit the end event for testability // Remark: Emit the end event for testability
self.emitter.emit('proxy', null, self.body); self.emitter.emit('proxy', null, self.body);
reverse_proxy.removeListener('error', error);
res.end(); res.end();
}); });
}); });
...@@ -207,7 +210,6 @@ HttpProxy.prototype = { ...@@ -207,7 +210,6 @@ HttpProxy.prototype = {
// At the end of the client request, we are going to stop the proxied request // At the end of the client request, we are going to stop the proxied request
req.addListener('end', function () { req.addListener('end', function () {
reverse_proxy.end(); reverse_proxy.end();
reverse_proxy.removeListener('error', error);
}); });
self.unwatch(req); self.unwatch(req);
...@@ -276,8 +278,6 @@ HttpProxy.prototype = { ...@@ -276,8 +278,6 @@ HttpProxy.prototype = {
var request = client.request('GET', req.url, headers); var request = client.request('GET', req.url, headers);
var errorListener = function (error) { var errorListener = function (error) {
p.emit('error', error);
request.emit('error', error);
socket.end(); 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