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) {
// For each data `chunk` received from the `reverseProxy`
// `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) {
if (req.method !== 'HEAD') {
res.write(chunk);
if (req.method !== 'HEAD' && res.writable) {
try {
res.write(chunk);
} catch (er) {
try {
res.end();
} catch (er) {}
}
}
});
......@@ -909,4 +917,4 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
if (options.buffer && !errState) {
options.buffer.resume();
}
};
\ No newline at end of file
};
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