http: avoid extra listener

PR-URL: https://github.com/nodejs/node/pull/28705
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
This commit is contained in:
Robert Nagy 2019-07-15 22:25:26 +02:00 committed by Rich Trott
parent 1721034a40
commit 2fd2dd7565

View File

@ -320,10 +320,6 @@ ClientRequest.prototype.abort = function abort() {
// If we're aborting, we don't care about any more response data.
if (this.res) {
this.res._dump();
} else {
this.once('response', (res) => {
res._dump();
});
}
// In the event that we don't have a socket, we will pop out of
@ -576,12 +572,11 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
// Add our listener first, so that we guarantee socket cleanup
res.on('end', responseOnEnd);
req.on('prefinish', requestOnPrefinish);
const handled = req.emit('response', res);
// If the user did not listen for the 'response' event, then they
// can't possibly read the data, so we ._dump() it into the void
// so that the socket doesn't hang there in a paused state.
if (!handled)
if (req.aborted || !req.emit('response', res))
res._dump();
if (method === 'HEAD')