hyper icon indicating copy to clipboard operation
hyper copied to clipboard

HTTP/2 103 Early Hints Support

Open apu031 opened this issue 2 weeks ago • 1 comments

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

  • Add InformationalConfig with callback system for processing 1xx informational responses
  • Extend HTTP/2 client builder with informational_responses() configuration method
  • Implement informational response polling in h2 client task with callback invocation
  • Support real-time processing of 103 Early Hints and other informational responses
  • Handle multiple informational responses before final response arrives

Server-side Support

  • Add InformationalSender extension for server-side hint transmission via mpsc channel
  • Implement server-side informational response forwarding using h2's send_informational API
  • Support multiple 103 Early Hints responses per request for progressive resource discovery
  • Validate informational responses and handle errors gracefully
  • Extend HTTP/1 informational support from initial prototype to HTTP/2

Complete Implementation

  • Build upon Joel Dice's initial HTTP/1 prototype (commit 4e2483a1) to add full HTTP/2 support
  • Integrate with h2 crate's informational response capabilities
  • Add robust error handling and validation
  • Include production-ready example with TLS, resource preloading, and performance monitoring
  • Provide extensive test coverage with 11 integration tests covering different scenarios

Changed Files

  • Cargo.toml: Example build configuration
  • examples/README.md: Document new HTTP/2 Early Hints example
  • examples/http2_early_hints.rs: Working example with TLS, and resource preloading
  • src/client/conn/http2.rs: Extend HTTP/2 client builder with informational response configuration
  • src/client/conn/informational.rs: New module implementing client-side informational callback system
  • src/client/conn/mod.rs: Export new informational module
  • src/proto/h1/dispatch.rs: Update HTTP/1 dispatch for informational compatibility
  • src/proto/h1/role.rs: Extend HTTP/1 role handling for informational responses
  • src/proto/h2/client.rs: HTTP/2 client informational response polling
  • src/proto/h2/server.rs: HTTP/2 server informational response forwarding
  • tests/integration-early-hints.rs: 11 integration tests covering:
    • Basic preconnect hints functionality
    • Resource preloading (CSS, JS, fonts, images)
    • Content Security Policy enforcement via Early Hints
    • Multiple sequential 103 responses
    • Mixed Link header types with HTTP/2 compression handling
    • Cross-origin redirect security behavior
    • Real-world web page optimization scenarios
    • Empty 103 response validation
    • Timing validation for performance benefits
    • Error response handling after hints sent

Use Cases Supported

  • 103 Early Hints: Enable early resource discovery and preloading for web performance optimization
  • 100 Continue: Support request/response optimization for large payloads
  • Resource Preloading: CSS, JavaScript, fonts, images, and fetch resources
  • CDN Preconnection: Early connection establishment to external domains
  • Progressive Enhancement: Multiple hint responses as server processing progresses

Technical Implementation

  • Informational responses sent without END_STREAM flag to maintain connection
  • Stream state management preserves HTTP/2 flow control during informational responses
  • Client callback system separates informational processing from main response flow
  • Server extension system allows middleware and applications to send hints seamlessly
  • Cross-origin security validated for redirect scenarios
  • Backward compatibility maintained - existing code continues to work unchanged

Standards Compliance

  • RFC 8297: Complete HTTP Status Code 103 Early Hints implementation
  • RFC 7540: HTTP/2 specification compliance for informational responses
  • HTTP/2 HPACK: Proper header compression handling for multiple Link headers
  • Browser Security: Cross-origin redirect protection and validation

Browser Tests

  • Chrome: Screenshot 2025-12-09 at 5 27 54 AM

  • Firefox: Screenshot 2025-12-09 at 5 29 33 AM


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.

apu031 avatar Dec 09 '25 12:12 apu031

Hello @dicej , @pablocm, @vikanezrimaya, @nox, @seanmonstar!

My commit originally builds on @dicej's prototype commit https://github.com/hyperium/hyper/commit/4e2483a101e286d0c80ca077cad1e594bdeb52c8 in PR - https://github.com/hyperium/hyper/pull/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 - https://github.com/hyperium/h2/pull/865

Thank you very much once again for your time and support. 🙏🏼

apu031 avatar Dec 09 '25 13:12 apu031