mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Add guards to every throw-able res.end call
This commit is contained in:
parent
62201a0917
commit
7bda25b1c6
@ -404,8 +404,13 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
// then respond with `404` since we do not have a valid proxy target.
|
||||
//
|
||||
if (!location) {
|
||||
res.writeHead(404);
|
||||
return res.end();
|
||||
try {
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
} catch (er) {
|
||||
console.error("res.writeHead/res.end error: %s", er.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
@ -480,7 +485,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
}
|
||||
}
|
||||
|
||||
res.end();
|
||||
try {
|
||||
res.end();
|
||||
} catch (er) {
|
||||
console.error("res.end error: %s", er.message);
|
||||
}
|
||||
}
|
||||
|
||||
outgoing = {
|
||||
@ -508,7 +517,12 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
|
||||
// `response.statusCode === 304`: No 'data' event and no 'end'
|
||||
if (response.statusCode === 304) {
|
||||
return res.end();
|
||||
try {
|
||||
res.end();
|
||||
} catch (er) {
|
||||
console.error("res.end error: %s", er.message)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// For each data `chunk` received from the `reverseProxy`
|
||||
@ -520,9 +534,12 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
try {
|
||||
res.write(chunk);
|
||||
} catch (er) {
|
||||
console.error("res.write error: %s", er.message);
|
||||
try {
|
||||
res.end();
|
||||
} catch (er) {}
|
||||
} catch (er) {
|
||||
console.error("res.end error: %s", er.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -535,7 +552,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
||||
response.on('end', function () {
|
||||
if (!errState) {
|
||||
reverseProxy.removeListener('error', proxyError);
|
||||
res.end();
|
||||
try {
|
||||
res.end();
|
||||
} catch (er) {
|
||||
console.error("res.end error: %s", er.message);
|
||||
}
|
||||
|
||||
// Emit the `end` event now that we have completed proxying
|
||||
self.emit('end', req, res);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user