Skip to content

Commit 6810b2b

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 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 4e2483a commit 6810b2b

File tree

11 files changed

+2156
-7
lines changed

11 files changed

+2156
-7
lines changed

Cargo.toml

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

7074
[features]
7175
# Nothing by default
@@ -85,7 +89,7 @@ http2 = ["dep:futures-channel", "dep:futures-core", "dep:h2"]
8589

8690
# Client/Server
8791
client = ["dep:want", "dep:pin-project-lite", "dep:smallvec"]
88-
server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec"]
92+
server = ["dep:httpdate", "dep:pin-project-lite", "dep:smallvec", "dep:futures-util"]
8993

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

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

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