Skip to content

Commit

Permalink
Revert "[refactor] Improved event handler cleanup "
Browse files Browse the repository at this point in the history
This reverts commit 9f92332.
  • Loading branch information
root committed Oct 25, 2011
1 parent 9f92332 commit c83d88e
Showing 1 changed file with 18 additions and 40 deletions.
58 changes: 18 additions & 40 deletions lib/node-http-proxy/http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,46 +236,24 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {

res.on('drain', ondrain);

function onend() {
cleanup();
res.end();
}

function onclose() {
cleanup();
res.destroy();
}

response.on('close', onclose);
response.on('end', onend);

response.on('error', proxyError);
res.on('error', proxyError);


function cleanup() {
response.removeListener('data', ondata);
res.removeListener('drain', ondrain);

response.removeListener('end', onend);
response.removeListener('close', onclose);

response.removeListener('error', proxyError);
res.removeListener('error', proxyError);

response.removeListener('end', cleanup);
response.removeListener('close', cleanup);

res.removeListener('end', cleanup);
res.removeListener('close', cleanup);
}

response.on('end', cleanup);
response.on('close', cleanup);

res.on('end', cleanup);
res.on('close', cleanup);

//
// When the `reverseProxy` `response` ends, end the
// corresponding outgoing `res` unless we have entered
// an error state. In which case, assume `res.end()` has
// already been called and the 'error' event listener
// removed.
//
response.on('end', function () {
if (!errState) {
reverseProxy.removeListener('error', proxyError);

try { res.end() }
catch (ex) { console.error("res.end error: %s", ex.message) }

// Emit the `end` event now that we have completed proxying
self.emit('end', req, res);
}
});
});

//
Expand Down

0 comments on commit c83d88e

Please sign in to comment.