feat(connect): add preferH2 connector option to offer h2 first in ALPN#5327
Open
Antamansid wants to merge 1 commit into
Open
feat(connect): add preferH2 connector option to offer h2 first in ALPN#5327Antamansid wants to merge 1 commit into
preferH2 connector option to offer h2 first in ALPN#5327Antamansid wants to merge 1 commit into
Conversation
The built-in connector hardcodes `ALPNProtocols: ['http/1.1', 'h2']` (h1 first) after spreading user options, so the order cannot be overridden via the `connect` options. Servers that select the ALPN protocol by *client* preference — some load balancers do — then negotiate `http/1.1` even with `allowH2: true`, forcing the client onto HTTP/1.1. Add an opt-in `preferH2` option that, together with `allowH2`, offers ALPN as `['h2', 'http/1.1']` (h2 first) so HTTP/2 is negotiated whenever the server supports it. The default behaviour is unchanged. If the server does not support HTTP/2, ALPN transparently falls back to `http/1.1`. Signed-off-by: antamansid <antamansid@mail.ru>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This relates to...
N/A — no existing issue. Affects clients talking to load balancers that select the ALPN protocol by client preference.
Rationale
The built-in connector hardcodes
ALPNProtocols: ['http/1.1', 'h2'](h1 first) after spreading user options (lib/core/connect.js), so the order cannot be overridden via theconnectoptions. Servers that select the ALPN protocol by client preference — some load balancers do (e.g. those relying on OpenSSL'sSSL_select_next_protosemantics) — then negotiatehttp/1.1even withallowH2: true, forcing the client onto HTTP/1.1.This adds an opt-in
preferH2connector option that, together withallowH2, offers ALPN as['h2', 'http/1.1'](h2 first), so HTTP/2 is negotiated whenever the server supports it. The default behaviour is unchanged (preferH2defaults tofalse). If the server does not support HTTP/2, ALPN transparently falls back tohttp/1.1.Changes
lib/core/connect.js: accept apreferH2build option; when set together withallowH2, offerALPNProtocols: ['h2', 'http/1.1']instead of the default['http/1.1', 'h2'].types/connector.d.ts: addpreferH2?: booleantoBuildOptions.docs/docs/api/Connector.md: document the new option.test/connect-h2-alpn-order.js: assert the offered ALPN order with and withoutpreferH2.test/types/connector.test-d.ts: type-level assertion forpreferH2.Features
preferH2(defaultfalse) to offer HTTP/2 first in ALPN, for servers that pick the protocol by client preference.Bug Fixes
N/A
Breaking Changes and Deprecations
N/A — the default ALPN order is unchanged;
preferH2is opt-in.Status