Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/conn/h1.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func handleH1Request(ctx context.Context, req *h1.Request, body []byte, handler

s := requestToStream(req, body)
defer s.Release()
rw := &h1ResponseAdapter{write: write, keepAlive: req.KeepAlive}
rw := &h1ResponseAdapter{write: write, keepAlive: req.KeepAlive, isHEAD: req.Method == "HEAD"}
s.ResponseWriter = rw

if err := handler.HandleStream(ctx, s); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/conn/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func putResponseBuffer(p *[]byte) {
type h1ResponseAdapter struct {
write func([]byte)
keepAlive bool
isHEAD bool
}

func (a *h1ResponseAdapter) WriteResponse(_ *stream.Stream, status int, headers [][2]string, body []byte) error {
Expand Down Expand Up @@ -88,7 +89,10 @@ func (a *h1ResponseAdapter) WriteResponse(_ *stream.Stream, status int, headers

buf = append(buf, crlf...)

if len(body) > 0 {
// RFC 9110 §9.3.2: HEAD responses MUST NOT contain a message body.
// Content-Length is still included above to indicate the size that
// would be returned for a GET, but no bytes are sent.
if len(body) > 0 && !a.isHEAD {
buf = append(buf, body...)
}

Expand Down