Skip to content

Commit

Permalink
fix(H2 Client): pause stream if response data is sent before response…
Browse files Browse the repository at this point in the history
… event
  • Loading branch information
st3ffgv4 committed Mar 23, 2024
1 parent cf6a5ea commit 9219ee3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ function writeH2 (client, request) {

/** @type {import('node:http2').ClientHttp2Stream} */
let stream
let isStreamResponseStarted = false

const { hostname, port } = client[kUrl]

Expand Down Expand Up @@ -388,6 +389,7 @@ function writeH2 (client, request) {
++session[kOpenStreams]

stream.once('response', headers => {
isStreamResponseStarted = true
const { [HTTP2_HEADER_STATUS]: statusCode, ...realHeaders } = headers
request.onResponseStarted()

Expand Down Expand Up @@ -419,7 +421,7 @@ function writeH2 (client, request) {
})

stream.on('data', (chunk) => {
if (request.onData(chunk) === false) {
if (!isStreamResponseStarted || request.onData(chunk) === false) {
stream.pause()
}
})
Expand Down

0 comments on commit 9219ee3

Please sign in to comment.