diff --git a/lib/dispatcher/client-h2.js b/lib/dispatcher/client-h2.js index 8155d6e226a..d593eae4fca 100644 --- a/lib/dispatcher/client-h2.js +++ b/lib/dispatcher/client-h2.js @@ -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', () => { @@ -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