h2 icon indicating copy to clipboard operation
h2 copied to clipboard

Implement HTTP/2 informational responses (1xx) support

Open apu031 opened this issue 1 month ago • 6 comments

Add support for HTTP/2 informational responses, enabling servers to send multiple 1xx status code responses before the final response and clients to receive them separately.

Key Features Added

Client-side Support

  • Add poll_informational() method to ResponseFuture for polling 1xx responses
  • Modify response polling logic to properly handle and skip informational headers
  • Ensure informational responses don't interfere with main response flow

Server-side Support

  • Add send_informational() method to SendResponse with documentation
  • Support multiple informational responses per request (e.g., 100 Continue, 103 Early Hints)
  • Validate that only 1xx status codes are sent as informational responses
  • Gracefully handle invalid informational responses without breaking the stream

Protocol Implementation

  • Add InformationalHeaders event type to distinguish from regular headers
  • Implement send_informational_headers_direct() for sending without state changes
  • Modify header processing to route informational responses correctly
  • Ensure informational responses don't affect HTTP/2 stream state transitions

Changed Files

  • Cargo.toml: Switch to local http crate dependency for extended status code support
  • src/client.rs: Add client-side informational response polling API
  • src/proto/streams/recv.rs: Implement informational header event handling and polling
  • src/proto/streams/send.rs: Add direct informational header sending capability
  • src/proto/streams/streams.rs: Integrate informational response methods into stream APIs
  • src/server.rs: Add server-side informational response API
  • tests/h2-tests/tests/informational_responses.rs: Add 6 unit tests * send_100_continue: Basic 100 Continue functionality * send_103_early_hints: 103 Early Hints with Link headers * send_multiple_informational_responses: Multiple 1xx responses in sequence * invalid_informational_status_returns_error: Invalid status code handling * client_poll_informational_responses: Client-side polling API * informational_responses_with_body_streaming: Streaming scenarios

Use Cases Supported

  • 100 Continue: Allow clients to continue sending request body
  • 103 Early Hints: Provide early resource hints for client preloading

Technical Notes

  • Informational responses are sent without the END_STREAM flag
  • Stream state remains unchanged when sending informational responses
  • Multiple informational responses can be sent before the final response
  • Client polling separates informational responses from the main response flow
  • Backward compatibility maintained - existing code continues to work unchanged

Resolves support for HTTP 103 Early Hints and 100 Continue HTTP/2 informational responses.

apu031 avatar Nov 19 '25 19:11 apu031

FWIW, there is also a new 104 status code for resumable uploads being standardized, so you can consider that another use case: https://www.ietf.org/archive/id/draft-ietf-httpbis-resumable-upload-10.html#section-5

LPardue avatar Nov 20 '25 14:11 LPardue

FWIW, there is also a new 104 status code for resumable uploads being standardized, so you can consider that another use case: https://www.ietf.org/archive/id/draft-ietf-httpbis-resumable-upload-10.html#section-5

@LPardue for sure! The PRs are the backbone for the informational codes support for hyper. I will add 104 specific examples once 103 related code is merged.

apu031 avatar Nov 20 '25 19:11 apu031

@seanmonstar @nox

Thank you both for your thoughtful reviews earlier. I truly appreciate the time and expertise you've shared on this PR.

I wanted to kindly follow up to see if there are any remaining concerns or blockers that I could address to help move this forward. This PR is a critical dependency for the final pull request in the hyper repository to complete the HTTP 103 Early Hints feature implementation, so merging it would be tremendously helpful.

Please let me know if there's anything I can clarify or improve. Thank you again for your consideration and support.

apu031 avatar Dec 01 '25 17:12 apu031

@seanmonstar, @vikanezrimaya, and @nox

Everything looks green. Could you please take a final look and merge this PR? I will go ahead and raise the next PR in Hyper repo for completing the 103 support.

Thanks for your time! Truly appreciate all the help.

apu031 avatar Dec 08 '25 17:12 apu031

@seanmonstar @nox

Waiting for this PR to be merged, while I have also raised the next PR for Hyper repository which will bring the 103 Early Hints feature to completion - https://github.com/hyperium/hyper/pull/3991.

Thanks again for your help.

apu031 avatar Dec 10 '25 17:12 apu031

Sorry for the wait, it's a larger amount of new code, and I've been swamped with finishing some other work for the end of the year. I appreciate your patience, I'm hopeful I have time to review more closely this afternoon 🤓

seanmonstar avatar Dec 12 '25 16:12 seanmonstar

Hi @seanmonstar

I truly appreciate the time you took to thoroughly review the code. No wonder Hyper keeps up raising the bar. I have addressed all the three concerns.

Wondering if it would be possible to get this PR merged before the holidays!

Hopefully after merging this and after the holidays, you would get some time to review the even longer PR for the hyper repo - https://github.com/hyperium/hyper/pull/3991/ 😅

Thanks again @seanmonstar! 🙏🏼

apu031 avatar Dec 17 '25 14:12 apu031