diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 5e9116c46..f6822b331 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -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) } } // @@ -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; } // @@ -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) } } } }); @@ -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); }