mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] Add guards to every throw-able res.end call
This commit is contained in:
parent
de4a6fe8a5
commit
e1c41d0694
@ -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`: No 'data' event and no 'end'
|
||||||
if (response.statusCode === 304) {
|
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 {
|
try {
|
||||||
res.write(chunk);
|
res.write(chunk);
|
||||||
}
|
}
|
||||||
catch (er) {
|
catch (ex) {
|
||||||
|
console.error("res.write error: %s", ex.message);
|
||||||
try { res.end() }
|
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 () {
|
response.on('end', function () {
|
||||||
if (!errState) {
|
if (!errState) {
|
||||||
reverseProxy.removeListener('error', proxyError);
|
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
|
// Emit the `end` event now that we have completed proxying
|
||||||
self.emit('end', req, res);
|
self.emit('end', req, res);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user