Skip to content

fix(http2): report zero body size for HEAD responses - #4237

Open
shuvroroy wants to merge 1 commit into
hyperium:masterfrom
shuvroroy:fix/http2-head-body-size-hint
Open

shuvroroy wants to merge 1 commit into
hyperium:masterfrom
shuvroroy:fix/http2-head-body-size-hint

Conversation

@shuvroroy

@shuvroroy shuvroroy commented Oct 18, 2026 •

Copy link
Copy Markdown

An HTTP/2 HEAD response with Content-Length: 5 currently exposes a body size hint of Some(5), even though HEAD responses contain no body bytes. This can mislead consumers that use size hints for allocation or body limits.

Carry the HEAD request flag into response mapping and give its incoming body an exact length of zero. Preserve the original Content-Length header and receive stream, including delayed completion and trailers.

The regression covers headers with END_STREAM, delayed empty DATA, trailers, a response without Content-Length, and a GET control. It fails on master with Some(5) instead of Some(0) and passes with this change.

Validation:

  • cargo test --features full: 329 passed, 10 ignored.

  • cargo clippy --features full -- -D warnings.

  • cargo check --no-default-features --features client,http2.

  • Repository Rust sources pass rustfmt --check --edition 2021.

  • The description, docs, and comments (words meant for humans) are written by a human, not by an LLM. (https://seanmonstar.com/micro/20260729-i-want-your-own-words/)

Carry the request method through response mapping and use an exact body
length of zero for HEAD responses. Their Content-Length describes the
corresponding GET representation, not the bytes in the response body.

Preserve the response header and receive stream so delayed completion and
trailers remain observable. Cover immediate completion, empty DATA,
trailers, missing Content-Length, and a GET response as a control.
@shuvroroy
shuvroroy marked this pull request as ready for review October 18, 2026 12:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant