Commit be3a0d84 authored by isaacs's avatar isaacs Committed by indexzero

Handle cases where res.write throws

parent 5d0bbb38
...@@ -513,9 +513,17 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { ...@@ -513,9 +513,17 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
// For each data `chunk` received from the `reverseProxy` // For each data `chunk` received from the `reverseProxy`
// `response` write it to the outgoing `res`. // `response` write it to the outgoing `res`.
// If the res socket has been killed already, then write()
// will throw. Nevertheless, try our best to end it nicely.
response.on('data', function (chunk) { response.on('data', function (chunk) {
if (req.method !== 'HEAD') { if (req.method !== 'HEAD' && res.writable) {
try {
res.write(chunk); res.write(chunk);
} catch (er) {
try {
res.end();
} catch (er) {}
}
} }
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment