-
-
Notifications
You must be signed in to change notification settings - Fork 746
feat(client): expose HTTP/2 flow-control options #4706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
82e71b9
feat(client): add http2 flow-control options under http2.{initialWind…
pabloelisseo 525f369
chore: add docs
pabloelisseo f63ea7f
refactor: remove http2 namespacing
pabloelisseo 70b0d7e
chore: increase defaults for initialWindowSize and connectionWindowSize
pabloelisseo 7c48018
refactor: extract applyConnectionWindowSize function
pabloelisseo 367641e
test: initialWindowSize and connectionWindowSize validations
pabloelisseo 866c81c
test: add types tests
pabloelisseo b46239e
chore: add reasoning for new defaults
pabloelisseo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| 'use strict' | ||
|
|
||
| const { tspl } = require('@matteo.collina/tspl') | ||
| const { test, after } = require('node:test') | ||
| const { EventEmitter } = require('node:events') | ||
| const connectH2 = require('../lib/dispatcher/client-h2') | ||
| const { | ||
| kUrl, | ||
| kSocket, | ||
| kMaxConcurrentStreams, | ||
| kHTTP2Session, | ||
| kHTTP2InitialWindowSize, | ||
| kHTTP2ConnectionWindowSize | ||
| } = require('../lib/core/symbols') | ||
|
|
||
| test('Should plumb initialWindowSize and connectionWindowSize into the HTTP/2 session creation path', async (t) => { | ||
| t = tspl(t, { plan: 6 }) | ||
|
|
||
| const http2 = require('node:http2') | ||
| const originalConnect = http2.connect | ||
|
|
||
| /** @type {any} */ | ||
| let seenConnectOptions = null | ||
| /** @type {number[]} */ | ||
| const setLocalWindowSizeCalls = [] | ||
|
|
||
| class FakeSession extends EventEmitter { | ||
| unref () {} | ||
| ref () {} | ||
| close () {} | ||
| destroy () {} | ||
| request () { | ||
| throw new Error('not implemented') | ||
| } | ||
|
|
||
| setLocalWindowSize (size) { | ||
| setLocalWindowSizeCalls.push(size) | ||
| } | ||
| } | ||
|
|
||
| class FakeSocket extends EventEmitter { | ||
| constructor () { | ||
| super() | ||
| this.destroyed = false | ||
| } | ||
|
|
||
| unref () {} | ||
| ref () {} | ||
| destroy () { | ||
| this.destroyed = true | ||
| return this | ||
| } | ||
| } | ||
|
|
||
| const fakeSession = new FakeSession() | ||
|
|
||
| http2.connect = function connectStub (_authority, options) { | ||
| seenConnectOptions = options | ||
| return fakeSession | ||
| } | ||
|
|
||
| after(() => { | ||
| http2.connect = originalConnect | ||
| }) | ||
|
|
||
| const initialWindowSize = 12345 | ||
| const connectionWindowSize = 77777 | ||
|
|
||
| const client = { | ||
| [kUrl]: new URL('https://localhost'), | ||
| [kMaxConcurrentStreams]: 100, | ||
| [kHTTP2InitialWindowSize]: initialWindowSize, | ||
| [kHTTP2ConnectionWindowSize]: connectionWindowSize, | ||
| [kSocket]: null, | ||
| [kHTTP2Session]: null | ||
| } | ||
|
|
||
| const socket = new FakeSocket() | ||
|
|
||
| connectH2(client, socket) | ||
|
|
||
| t.ok(seenConnectOptions && seenConnectOptions.settings) | ||
| t.strictEqual(seenConnectOptions.settings.enablePush, false) | ||
| t.strictEqual( | ||
| seenConnectOptions.settings.initialWindowSize, | ||
| initialWindowSize | ||
| ) | ||
| t.strictEqual(client[kHTTP2Session], fakeSession) | ||
|
|
||
| // Emit 'connect' event | ||
| process.nextTick(() => { | ||
| fakeSession.emit('connect') | ||
| }) | ||
|
|
||
| await new Promise((resolve) => process.nextTick(resolve)) | ||
|
|
||
| t.strictEqual(setLocalWindowSizeCalls.length, 1) | ||
| t.strictEqual(setLocalWindowSizeCalls[0], connectionWindowSize) | ||
|
|
||
| await t.completed | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have slightly better defaults than Node.js core for these.
See @ronag in nodejs/node#61036