diff --git a/lib/_http_client.js b/lib/_http_client.js index 11e946c893b7c3..a37df35f295e2d 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -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 @@ -572,12 +568,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')