HTTP/2 103 Early Hints Support#4114
Open
apu031 wants to merge 2 commits into
Open
Conversation
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>
Author
Accidentally forced pushed the branch so recreating the PR (Previous PR #3991) |
Author
|
Hi @seanmonstar, It is no doubt that maintaining hyper is super demanding of your time. The HTTP 103 support from hyper is blocking some internal work for us. So requesting your precious time to get the PR #3991 (now PR #4114) to the finish line since it has been open for the last 8 months. I promise I will promptly address any concerns you have to save your time following your review. Truly appreciate the help, @seanmonstar ! |
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 hyperium#3980, hyperium#2426
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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