Skip to content

feat(http2): add a pooled, multiplexed HTTP/2 http.Client - #1956

Open
demolaf wants to merge 14 commits into
dart-lang:masterfrom
demolaf:pooled-http2-client
Open

feat(http2): add a pooled, multiplexed HTTP/2 http.Client#1956
demolaf wants to merge 14 commits into
dart-lang:masterfrom
demolaf:pooled-http2-client

Conversation

@demolaf

@demolaf demolaf commented Jul 30, 2026

Copy link
Copy Markdown

Closes #1385

Adds Http2Client, a pooled, multiplexed http.Client backed by HTTP/2 connections, plus the generic ClientPool<T> it's built on — fixes dart:io's HttpClient opening one connection per concurrent request. Ported and generalized from a downstream implementation built for firebase/firebase-admin-dart#305.

  • ClientPool<T>: most-full-first packing, idle GC, failure retirement, awaitable graceful terminate()
  • Http2Client: pools per host:port, caps concurrent handshakes globally, multi-host safe (e.g. as googleapis_auth's baseClient)
  • Retries once when a pooled connection was closed by the peer before reuse
  • Added unit tests for ClientPool and integration tests for Http2Client covering multi-host pooling, connection-cap dialing, graceful terminate, and the peer-close retry

@demolaf
demolaf marked this pull request as draft July 30, 2026 09:43
@demolaf
demolaf marked this pull request as ready for review July 30, 2026 13:14
Comment thread pkgs/http2/lib/src/http2_client.dart
Comment thread pkgs/http2/lib/src/http2_client.dart Outdated
Comment thread pkgs/http2/lib/src/client_pool.dart Outdated
Comment thread pkgs/http2/lib/src/client_pool.dart Outdated
Comment thread pkgs/http2/lib/src/client_pool.dart Outdated
Comment thread pkgs/http2/lib/src/client_pool.dart Outdated
Comment thread pkgs/http2/lib/src/http2_client.dart
Comment thread pkgs/http2/lib/src/http2_client.dart Outdated
Comment thread pkgs/http2/lib/src/http2_client.dart Outdated
Comment thread pkgs/http2/test/http2_client_test.dart Outdated

@brianquinlan brianquinlan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have more review feedback tomorrow. Also, this PR adds (preliminary) conformance tests: #1960

You might want to add them to this PR.

/// networks - do not use it to accept arbitrary certificates in production.
class Http2Client extends BaseClient {
Http2Client({
this.maxStreamsPerConnection = 100,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this default to SETTINGS_MAX_CONCURRENT_STREAMS send by the server?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this should read SETTINGS_MAX_CONCURRENT_STREAMS returned from the server. i'll make that change now

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_settingsHandler.peerSettings.maxConcurrentStreams isn't exposed in the public API as of now. So I'll need to add a getter e.g. peerMaxConcurrentStreams on ClientTransportConnection which can then be used in Http2Client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a http.Client compatible client

3 participants