http: fix http client leaky with double response

PR-URL: https://github.com/nodejs/node/pull/60062
Fixes: https://github.com/nodejs/node/issues/60025
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
theanarkh
2025-10-13 23:58:26 +08:00
committed by GitHub
parent 8bc7dfd16f
commit 59b70e5fe3
3 changed files with 57 additions and 3 deletions

View File

@@ -41,6 +41,7 @@ const {
} = incoming;
const kIncomingMessage = Symbol('IncomingMessage');
const kSkipPendingData = Symbol('SkipPendingData');
const kOnMessageBegin = HTTPParser.kOnMessageBegin | 0;
const kOnHeaders = HTTPParser.kOnHeaders | 0;
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
@@ -126,7 +127,7 @@ function parserOnBody(b) {
const stream = this.incoming;
// If the stream has already been removed, then drop it.
if (stream === null)
if (stream === null || stream[kSkipPendingData])
return;
// Pretend this was the result of a stream._read call.
@@ -141,7 +142,7 @@ function parserOnMessageComplete() {
const parser = this;
const stream = parser.incoming;
if (stream !== null) {
if (stream !== null && !stream[kSkipPendingData]) {
stream.complete = true;
// Emit any trailing headers.
const headers = parser._headers;
@@ -310,4 +311,5 @@ module.exports = {
HTTPParser,
isLenient,
prepareError,
kSkipPendingData,
};