Handle cases where res.write throws

This commit is contained in:
isaacs 2011-08-27 11:52:05 -07:00 committed by indexzero
parent 5d0bbb38c3
commit be3a0d84a1

View File

@ -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) {}
}
}
});