Repository navigation
fix(client): treat 204, 205 and 304 responses as having no body - #4289
Open
waw666waw666 wants to merge 1 commit into
Open
waw666waw666 wants to merge 1 commit into
waw666waw666 wants to merge 1 commit into
Conversation
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
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.
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: 5and no body, the client waits for five bytes that willnever arrive and the connection hangs. The HTTP/2 client has the same blind
spot: it trusts
Content-Lengthfor 204, 205 and 304 when reportingsize_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_CONTENTand
NOT_MODIFIEDnow map to asize_hintof zero, the same way HEADalready does. The
Content-Lengthheader itself and the receive streamare left untouched.
Two tests in
tests/client.rscover it: an HTTP/1 test where a 205 withContent-Length: 5must report an exact size of zero and collect to anempty body at once instead of hanging, and an HTTP/2 test for the 204/304
size hints.
cargo test --features fullpasses, as docargo fmt --checkand
cargo clippy --features full -- -D warnings.Fixes the client side of #4261.