Skip to content

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Jan 19, 2026

Summary

  • Force connection close after 204/304 responses to prevent corruption from protocol-violating servers
  • Per RFC 7230 Section 3.3.3, 204 and 304 responses have no body regardless of headers
  • Matches the approach used by httpx (Python) and similar to curl's fix

Fixes #434

Per RFC 7230 Section 3.3.3, responses with status codes 204 (No Content)
and 304 (Not Modified) MUST NOT contain a message body, regardless of
any Content-Length or Transfer-Encoding headers.

If a misbehaving server sends such headers, reading the body could leave
bytes in the socket that corrupt subsequent requests on a reused
connection.

This fix forces connection close after 204/304 responses to prevent any
potential corruption from protocol-violating servers. This matches the
approach taken by other HTTP clients like httpx (Python).

Fixes #434
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.

204 with no body hangs on second attempt after reading body

2 participants