Conversation
|
Hello @dicej , @pablocm, @vikanezrimaya, @nox, @seanmonstar! My commit originally builds on @dicej's prototype commit 4e2483a in PR - #3815. However, this code is obsolete and does not build anymore. Therefore, I have included both the commits in my PR. @seanmonstar @nox let me know if this would be the right way to move forward. The code changes follow the proposed public API suggested from @vikanezrimaya. After merging this, I will release a PR for Axum wrapper. Note - The tests will pass once we merge the h2 repo's PR - hyperium/h2#865 Thank you very much once again for your time and support. 🙏🏼 |
This is a prototype intended to spur discussion about what support for 1xx informational responses should look like in a Hyper server. The good news is that it works great (for HTTP/1 only, so far). The bad news is it's kind of ugly. Here's what I did: - Add `ext::InformationalSender`, a type which wraps a `futures_channel::mspc::Sender<Response<()>>`. This may be added as an extension to an inbound `Request` by the Hyper server, and the application and/or middleware may use it to send one or more informational responses before sending the real one. - Add code to `proto::h1::dispatch` and friends to add such an extension to each inbound request and then poll the `Receiver` end along with the future representing the final response. If the app never sends any informational responses, then everything proceeds as normal. Otherwise, we send those responses as they become available until the final response is ready. TODO items: - [ ] Also support informational responses in the HTTP/2 server. - [ ] Determine best way to handle when the app sends an informational response with a non-1xx status code. Currently we just silently ignore it. - [ ] Come up with a less hacky API? - [ ] Add test coverage. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
JakubKoralewski
left a comment
There was a problem hiding this comment.
Hi, I'm interested in 10x support so thought I'd contribute a review. Thanks for this work. I am not a contributor just hope to make it easier to review for someone in charge.
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 hyperium#3980, hyperium#2426
Hey Jakub (@JakubKoralewski), I wanted to take a moment to express my sincere gratitude for the exceptional code review you provided on this PR. Your thorough analysis and insightful feedback have been absolutely invaluable, and I genuinely mean it when I say this PR is significantly better because of your input. |
|
Hey @seanmonstar, and @nox! I guess things are going super busy as the new year started. Truly appreciate your feedback and effort on the last hyperium/h2#865. Could you please take a look into this PR? Hopefully, we get it merged soon for everyone to use it. Thanks! |
Implement HTTP/2 103 Early Hints Support
Add complete HTTP/2 103 Early Hints implementation with full client and server support, building upon the initial 1xx informational responses prototype to deliver a solution for web performance optimization.
Key Features Added
Client-side Support
InformationalConfigwith callback system for processing 1xx informational responsesinformational_responses()configuration methodServer-side Support
.enable_informational()method for explicit feature activationEarlyHintsPusherhandle when feature enabledEarlyHintsError::NotSupportedwhen feature not enabledInformationalSenderextension for hint transmission via mpsc channelComplete Implementation
Changed Files
early_hints_pusher()APIenable_informationalconfig field (defaults to false), conditional channel creation, helper method for polling logic.enable_informational()builder methodTest Coverage
Integration Tests (11 tests, ~0.27s)
All tests pass consistently, covering:
Unit Tests (18 tests, ~0.24s)
Documentation Tests (2 tests)
early_hints_pusher()usage.enable_informational()builder methodTotal: 152 tests passing (31 new from this PR)
API Usage Example
Server-side (Requires Opt-in)
Use Cases Supported
Technical Implementation
Standards Compliance
Migration Path
This implementation is fully backward compatible with opt-in behavior:
No Changes Required
Existing applications continue to work unchanged with zero performance impact.
To Enable Feature
Add single builder method call:
Then use early_hints_pusher() in handlers:
No breaking changes. Pay only for what you use.
Browser Tests
The implementation provides a robust foundation for web performance optimization while maintaining the reliability and safety expected from the hyper HTTP library.
Resolves #3980 and #2426 for HTTP/2 103 Early Hints support and extends the informational responses capability for HTTP/2 protocols.
Revision 2
Addresses @JakubKoralewski 's feedback
This implementation addresses all concerns raised during code review:
informational_pusherpattern