Skip to content

Commit

Permalink
Moved error handling to response.on('end'), fixed error handling in w…
Browse files Browse the repository at this point in the history
…ebsocket's part
  • Loading branch information
indutny committed Sep 17, 2010
1 parent 56003b5 commit 7e61f0c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/node-http-proxy.js
Expand Up @@ -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();
};

Expand Down Expand Up @@ -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();
});
});
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 7e61f0c

Please sign in to comment.