Skip to content

fix: force connection close for 204/304 responses (#434) - #815

Merged
benoitc merged 1 commit into
masterfrom
fix/434-204-no-body
Jan 20, 2026
Merged

benoitc merged 1 commit into
masterfrom
fix/434-204-no-body

Conversation

@benoitc

@benoitc benoitc commented Jan 19, 2026

Copy link
Copy Markdown
Owner

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
@benoitc
benoitc merged commit 496df7c into master Jan 20, 2026
5 checks passed
@benoitc
benoitc deleted the fix/434-204-no-body branch January 20, 2026 07:03
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

1 participant