Repository navigation
feat: make HTTP/2 a cargo feature - #45
Merged
Merged
Conversation
BKPepe
force-pushed
the
feat-http2-feature
branch
from
November 10, 2026 10:56
984960d to
ddbbca1
Compare
--http2 has to be asked for, yet h2 was compiled into every build. It is now the http2 feature, part of the default set, so the release tarballs and cargo install do not change. A build without it hides --http2 from --help and refuses it, instead of quietly running the test over HTTP/1.1. In the shape OpenWrt builds, the binary is 12.5 % smaller that way, 877 KB against 1003 KB with gzip on aarch64, and links 133 crates instead of 140. The OpenWrt package builds with --no-default-features, so it leaves HTTP/2 out. CI tests rustls-tls and native-tls each with and without http2, and the MSRV job checks all four.
The backend of the integration tests is plain HTTP/1.1, so nothing checked ALPN or h2 against a real handshake. tests/alpn.rs runs the binary against a rustls server in the test process and records what the client offers, what is agreed and the first bytes it sends. Without --http2 neither backend sends ALPN and the client speaks HTTP/1.1. With it the client offers h2 and http/1.1, sends the HTTP/2 preface when h2 is agreed, and falls back to HTTP/1.1 when the server picks http/1.1 or does not use ALPN. rustls is a dev-dependency, so the test also runs with native-tls. The comment in tls.rs said hyper-rustls sets ALPN from enable_http1(). It leaves ALPN empty then.
BKPepe
force-pushed
the
feat-http2-feature
branch
from
November 15, 2026 02:02
ddbbca1 to
22c6d48
Compare
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.
--http2is opt-in at run time, but h2 was compiled into every build. This makes it thehttp2cargo feature. It is in the default set, so release tarballs andcargo installstay as they are.A build without it hides
--http2from--helpand refuses it withthis build has no HTTP/2 support, so --http2 cannot be used. h2 is then gone from the dependency tree, dev-dependencies included:cargo tree -e features -i h2--no-default-features --features native-tls--no-default-features --features rustls-tls--no-default-features --features native-tls,http2Size of native-tls builds from the same commit, Rust 1.96.1, aarch64-unknown-linux-gnu, with OpenWrt's release profile (opt-level z, LTO, codegen-units 1, panic unwind), stripped:
http2gzip -9The OpenWrt package builds with
--no-default-features, so the first release with this change drops HTTP/2 there. A Config.in switch, off by default, will bring it back for those who want it.tests/alpn.rsruns the binary against a TLS server in the test process and checks what the client offers in ALPN and which protocol it then speaks. Without--http2neither backend sends ALPN and the client speaks HTTP/1.1. With it the client offers h2 and http/1.1, speaks HTTP/2 when h2 is agreed and falls back to HTTP/1.1 otherwise. CI now tests rustls-tls and native-tls each with and withouthttp2, and the MSRV job checks all four.Checked on Linux: fmt, clippy and
cargo testfor all four combinations, andcargo checkwith Rust 1.93.1 for all four. By hand against nginx with HTTP/2 enabled: builds without the feature refuse--http2and speak HTTP/1.1, builds with it speak HTTP/2 with--http2and HTTP/1.1 without.