Skip to content

Commit 4a2f776

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 7950930 commit 4a2f776

File tree

14 files changed

+2594
-10
lines changed

14 files changed

+2594
-10
lines changed

Cargo.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ atomic-waker = { version = "1.1.2", optional = true }
3131
futures-channel = { version = "0.3", optional = true }
3232
futures-core = { version = "0.3.31", optional = true }
3333
futures-util = { version = "0.3", default-features = false, features = ["alloc"], optional = true }
34-
h2 = { version = "0.4.2", optional = true }
34+
h2 = { version = "0.4.13", optional = true }
3535
http-body-util = { version = "0.1", optional = true }
3636
httparse = { version = "1.9", optional = true }
3737
httpdate = { version = "1.0", optional = true }
@@ -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)