Skip to content

fix(client): treat 204, 205 and 304 responses as having no body - #4289

Open
waw666waw666 wants to merge 1 commit into
hyperium:masterfrom
waw666waw666:fix/client-205-no-body
Open

waw666waw666 wants to merge 1 commit into
hyperium:masterfrom
waw666waw666:fix/client-205-no-body

Conversation

@waw666waw666

Copy link
Copy Markdown

A 205 response cannot carry a body (RFC 9110 §15.3.6), but the client
only treats 204 and 304 that way. When an HTTP/1 server answers 205 with
Content-Length: 5 and no body, the client waits for five bytes that will
never arrive and the connection hangs. The HTTP/2 client has the same blind
spot: it trusts Content-Length for 204, 205 and 304 when reporting
size_hint, so callers are told to expect bytes that do not exist.

This is the client side of #4261. #4262 fixes the server side; this one
fixes the client side only.

The fix is small. In the HTTP/1 client decoder, 205 joins 204 and 304 in
the zero-length set. In the HTTP/2 client, NO_CONTENT, RESET_CONTENT
and NOT_MODIFIED now map to a size_hint of zero, the same way HEAD
already does. The Content-Length header itself and the receive stream
are left untouched.

Two tests in tests/client.rs cover it: an HTTP/1 test where a 205 with
Content-Length: 5 must report an exact size of zero and collect to an
empty body at once instead of hanging, and an HTTP/2 test for the 204/304
size hints. cargo test --features full passes, as do cargo fmt --check
and cargo clippy --features full -- -D warnings.

Fixes the client side of #4261.

A 205 (Reset Content) response must not contain a body (RFC 9110
Section 15.3.6), but the HTTP/1 client decoder only special-cased
204 and 304: a 205 response carrying Content-Length was decoded as a
sized body, so the client waited forever for body bytes that a
compliant server never sends. Add 205 to the zero-length arm,
alongside 204 and 304.

Apply the same rule to the HTTP/2 client mapping, which only
special-cased HEAD (hyperium#4237): 204, 205 and 304 responses now report a
zero body size instead of trusting Content-Length.

Fixes the client side of hyperium#4261 (whose open PR hyperium#4262 covers only the
server side).

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