Skip to content

Commit 16e131e

Browse files
author
Apu Islam
committed
feat(http2): implement 103 Early Hints support
Add complete HTTP/2 103 Early Hints implementation with client and server support: - Add InformationalSender extension for server-side hint transmission via mpsc channel - Create InformationalCallback system for client-side informational response handling - Extend HTTP/2 client builder with informational_responses() configuration method - Implement informational response polling in h2 client task with callback invocation - Add server-side informational response forwarding using h2's send_informational API - Include extensive integration tests covering multiple scenarios and edge cases - Add `enable_informational` config field (defaults to false) and conditional channel creation per request - Add complete working example with TLS, resource preloading, and performance monitoring - Update Cargo.toml with local h2 dependency and example build configuration The implementation enables servers to send resource preload hints before final responses, allowing browsers to start downloading critical resources early and improve page load performance. Clients can register callbacks to process 103 Early Hints and other informational responses. Closes #3980, #2426
1 parent 46eef50 commit 16e131e

14 files changed

Lines changed: 2593 additions & 9 deletions

File tree

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ tokio = { version = "1", features = [
6767
] }
6868
tokio-test = "0.4"
6969
tokio-util = "0.7.10"
70+
# Additional dependencies for HTTP/2 Early Hints example
71+
rcgen = "0.12"
72+
tokio-rustls = "0.25"
73+
rustls-pemfile = "2.0"
7074

7175
[features]
7276
# Nothing by default
@@ -86,7 +90,7 @@ http2 = ["dep:atomic-waker", "dep:futures-channel", "dep:futures-core", "dep:h2"
8690

8791
# Client/Server
8892
client = ["dep:want", "dep:pin-project-lite", "dep:smallvec"]
89-
server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec"]
93+
server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec", "dep:futures-util"]
9094

9195
# C-API support (currently unstable (no semver))
9296
ffi = ["dep:http-body-util", "dep:futures-util"]
@@ -305,6 +309,11 @@ name = "web_api"
305309
path = "examples/web_api.rs"
306310
required-features = ["full"]
307311

312+
[[example]]
313+
name = "http2_early_hints"
314+
path = "examples/http2_early_hints.rs"
315+
required-features = ["full"]
316+
308317

309318
[[bench]]
310319
name = "body"

examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ futures-util = { version = "0.3", default-features = false }
3838

3939
* [`echo`](echo.rs) - An echo server that copies POST request's content to the response content.
4040

41+
* [`http2_early_hints`](http2_early_hints.rs) - An HTTP/2 server that sends 103 Early Hints.
42+
4143
## Going Further
4244

4345
* [`gateway`](gateway.rs) - A server gateway (reverse proxy) that proxies to the `hello` service above.

0 commit comments

Comments
 (0)