Skip to content

Commit

Permalink
fix(H2 Client): bind stream 'data' listener only after received 'resp…
Browse files Browse the repository at this point in the history
…onse' event (#2985)

* fix(fetch): pause stream if data is received before headers in HTTP/2

* Revert "fix(fetch): pause stream if data is received before headers in HTTP/2"

This reverts commit cd2eaf4.

* fix(H2 Client): pause stream if response data is sent before response event

* Revert "fix(H2 Client): pause stream if response data is sent before response event"

This reverts commit 9219ee3.

* fix(H2 Client): bind stream 'data' listener once 'response' is triggered

ref: https://nodejs.org/api/http2.html#clienthttp2sessionrequestheaders-options

---------

Co-authored-by: Stefano <stefano@agaweb.it>
  • Loading branch information
st3ffgv4 and stefanoaga committed Mar 25, 2024
1 parent 0ec5a40 commit c9acca9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ function writeH2 (client, request) {
if (request.onHeaders(Number(statusCode), realHeaders, stream.resume.bind(stream), '') === false) {
stream.pause()
}

stream.on('data', (chunk) => {
if (request.onData(chunk) === false) {
stream.pause()
}
})
})

stream.once('end', () => {
Expand All @@ -418,12 +424,6 @@ function writeH2 (client, request) {
util.destroy(stream, err)
})

stream.on('data', (chunk) => {
if (request.onData(chunk) === false) {
stream.pause()
}
})

stream.once('close', () => {
session[kOpenStreams] -= 1
// TODO(HTTP/2): unref only if current streams count is 0
Expand Down

0 comments on commit c9acca9

Please sign in to comment.