Skip to content

Commit

Permalink
[fix] Add guards to every throw-able res.end call
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Aug 29, 2011
1 parent de4a6fe commit e1c41d0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/node-http-proxy/http-proxy.js
Expand Up @@ -178,7 +178,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
}
}

res.end();
try { res.end() }
catch (ex) { console.error("res.end error: %s", ex.message) }
}

//
Expand Down Expand Up @@ -209,7 +210,9 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {

// If `response.statusCode === 304`: No 'data' event and no 'end'
if (response.statusCode === 304) {
return res.end();
try { res.end() }
catch (ex) { console.error("res.end error: %s", ex.message) }
return;
}

//
Expand All @@ -223,9 +226,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
try {
res.write(chunk);
}
catch (er) {
catch (ex) {
console.error("res.write error: %s", ex.message);
try { res.end() }
catch (er) {}
catch (ex) { console.error("res.write error: %s", ex.message) }
}
}
});
Expand All @@ -240,8 +244,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
response.on('end', function () {
if (!errState) {
reverseProxy.removeListener('error', proxyError);
res.end();


try { res.end() }
catch (ex) { console.error("res.end error: %s", ex.message) }

// Emit the `end` event now that we have completed proxying
self.emit('end', req, res);
}
Expand Down

0 comments on commit e1c41d0

Please sign in to comment.