Skip to content

fix: suppress response body for HEAD requests (RFC 9110)#50

Merged
FumingPower3925 merged 1 commit intomainfrom
fix/head-response-body
Mar 9, 2026
Merged

fix: suppress response body for HEAD requests (RFC 9110)#50
FumingPower3925 merged 1 commit intomainfrom
fix/head-response-body

Conversation

@FumingPower3925
Copy link
Contributor

Summary

  • Bug: H1 response writer sent body bytes for HEAD requests, violating RFC 9110 §9.3.2. On keep-alive connections, the unread body data corrupted subsequent responses — the client parsed leftover bytes (e.g., HEAD /test) concatenated with the next response's status line as a malformed status code (/testHTTP/1.1).
  • Fix: Added isHEAD flag to h1ResponseAdapter. When set, WriteResponse includes Content-Length (indicating what a GET would return) but omits the body bytes.

This was the root cause of the TestConformanceMatrix/epoll/auto/BasicMethods/OPTIONS failure in the v0.3.5 release.

Test plan

  • Conformance tests pass: go test -race ./test/conformance/...
  • Verify epoll/auto/BasicMethods/OPTIONS no longer fails
  • Verify no "Unsolicited response received on idle HTTP channel" warnings

HEAD responses must not contain a message body. The server was sending
body bytes for HEAD, which corrupted subsequent keep-alive responses:
the unread body data merged with the next response's status line,
causing "malformed HTTP status code" errors (e.g., /testHTTP/1.1).

Content-Length is still included to indicate what a GET would return.
@FumingPower3925 FumingPower3925 merged commit df1fc0d into main Mar 9, 2026
9 checks passed
@FumingPower3925 FumingPower3925 deleted the fix/head-response-body branch March 9, 2026 21:09
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