Skip to content

Commit

Permalink
Handle cases where res.write throws
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs authored and indexzero committed Aug 28, 2011
1 parent 5d0bbb3 commit be3a0d8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/node-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
}
});

Expand Down Expand Up @@ -909,4 +917,4 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
if (options.buffer && !errState) {
options.buffer.resume();
}
};
};

0 comments on commit be3a0d8

Please sign in to comment.