Skip to content

server: ConnectionConfig — one per-connection settings value held by Server and BoundServer - #307

Merged
iainmcgin merged 2 commits into
mainfrom
rpb/b-connection-config
Sep 18, 2026
Merged

iainmcgin merged 2 commits into
mainfrom
rpb/b-connection-config

Conversation

@rpb-ant

@rpb-ant rpb-ant commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Implements #250 items 2–3, modelled on ClientConfig from #247. Most of the server.rs diff moves the long setter docs from BoundServer onto ConnectionConfig; git diff --color-moved=dimmed-zebra separates the moves from the edits.

Before this, nine per-connection fields were duplicated on Server and BoundServer, with four hand-synchronised default blocks and a nine-argument serve_with_listener. After, each builder holds one value, and the same value configures either:

let config = ConnectionConfig::new()
    .with_max_connection_age(Duration::from_secs(600))
    .with_http2_max_header_list_size(64 << 10);
Server::new(router).with_connection_config(config.clone()).serve(addr).await?;
// or: Server::bind(addr).await?.with_connection_config(config).serve(router).await?;
  • Public ConnectionConfig, also at the crate root (#[non_exhaustive]; derives Clone, Debug, PartialEq, Eq), holds every setting the builders apply to a connection. The builders' existing with_* setters keep their signatures and edit that value; with_connection_config / connection_config() replace or return it whole.
  • New setting with_http2_max_header_list_size(u32), the advertised SETTINGS_MAX_HEADER_LIST_SIZE (hyper's 16 KiB default is too small for some bearer tokens), with shorthands on Server and BoundServer. It panics on zero. A request whose header list reaches the limit gets 431. With h2 0.4.15 and later, a connection-closing GOAWAY follows a header list past four times the limit, or a header block spread over more CONTINUATION frames than h2 allows, which can happen well under four times the limit.
  • The TLS settings move into a crate-private AcceptConfig, so the accept loop is serve_with_listener(listener, service, accept, config, shutdown) in every feature set.

rpb-ant and others added 2 commits September 17, 2026 22:40
…y `Server` and `BoundServer`

The nine per-connection fields duplicated across `Server`, `BoundServer`,
their four default blocks, `serve_with_listener`'s positional parameters
and `serve_accepted_stream` become one public `#[non_exhaustive]`
`ConnectionConfig` (private fields, `new`, `with_*` setters, plain
accessors, `Default`) in the `ClientConfig` shape. `Server` and
`BoundServer` each hold one; their existing `with_*` setters forward to
it and `with_connection_config` / `connection_config()` take or expose
it whole, so the two builders cannot drift and a configuration crosses
between them. The TLS pair is grouped the same way in a crate-private
`AcceptConfig`, so the accept loop takes `(listener, service, accept,
config, shutdown)` in every feature set. `Http2Config`,
`RetirementConfig` and the `build_*_config` helpers are gone; max-age
jitter is drawn inside the driver.

Adds `ConnectionConfig::with_http2_max_header_list_size`, wired to
hyper's HTTP/2 builder.

Tests: the per-topic builder round-trip tests are consolidated into
`ConnectionConfig` unit tests plus one test that every forward on both
builders edits the field of the same name and that one value crosses
between them; an h2 client sees `431` for headers over the configured
list size.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BgcfmMV1ECyzhbqGvUV1a7
Signed-off-by: Ryan Brewster <rpb@anthropic.com>
`with_http2_max_header_list_size(0)` left a server that closed every
connection on its first request. It now panics, like
`with_max_concurrent_streams(0)`. The docs also said oversized headers
get `431`, which only holds up to four times the limit: past that, h2
closes the whole connection with `GOAWAY(ENHANCE_YOUR_CALM)`. The docs,
the changelog fragment and the test now cover that boundary.

`Server` and `BoundServer` get the matching shorthand setter, as they
have for every other connection setting.

Signed-off-by: Iain McGinniss <309153+iainmcgin@users.noreply.github.com>
@iainmcgin
iainmcgin force-pushed the rpb/b-connection-config branch from 314acde to 9db55d1 Compare September 18, 2026 05:41
@iainmcgin
iainmcgin marked this pull request as ready for review September 18, 2026 05:41

@iainmcgin iainmcgin 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.

[claude code] Approving under the maintainers' agreement to review and merge each other's PRs. Rebased onto main after #306 merged; the added fix commits went through code, API, doc and deslop review.

@iainmcgin
iainmcgin enabled auto-merge September 18, 2026 05:41
@iainmcgin
iainmcgin added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit c439fde Sep 18, 2026
14 checks passed
@iainmcgin
iainmcgin deleted the rpb/b-connection-config branch September 18, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants