Skip to content

Commit 9912595

Browse files
author
Apu Islam
committed
feat(http2): implement 103 Early Hints support
Add HTTP/2 103 Early Hints implementation with client and server support: - Add builder opt-in pattern via enable_informational() for zero-cost abstraction - Create early_hints_pusher() API for server-side hint transmission via mpsc channel - Add 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 test coverage: 11 integration tests, 18 unit tests, 2 doc tests - Add complete working example with TLS, resource preloading, and performance monitoring - Update Cargo.toml with h2 = 0.4.13 dependency requirement 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. Feature is opt-in and disabled by default for zero overhead when not used. Clients can register callbacks to process 103 Early Hints and other informational responses. Closes #3980, #2426
1 parent 4b30501 commit 9912595

File tree

14 files changed

+2593
-9
lines changed

14 files changed

+2593
-9
lines changed

Cargo.toml

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

6973
[features]
7074
# Nothing by default
@@ -84,7 +88,7 @@ http2 = ["dep:futures-channel", "dep:futures-core", "dep:h2"]
8488

8589
# Client/Server
8690
client = ["dep:want", "dep:pin-project-lite", "dep:smallvec"]
87-
server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec"]
91+
server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec", "dep:futures-util"]
8892

8993
# C-API support (currently unstable (no semver))
9094
ffi = ["dep:http-body-util", "dep:futures-util"]
@@ -201,6 +205,11 @@ name = "web_api"
201205
path = "examples/web_api.rs"
202206
required-features = ["full"]
203207

208+
[[example]]
209+
name = "http2_early_hints"
210+
path = "examples/http2_early_hints.rs"
211+
required-features = ["full"]
212+
204213

205214
[[bench]]
206215
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)