http3: discard body from responses to HEAD requests (#4115)

* http3: HEAD method should not have a body

* add tests

* Update http3/server.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* ruduce the size of responseWriter

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
Glonee
2023-10-23 10:31:24 +08:00
committed by GitHub
parent a263164d9f
commit 36f7fe7d07
3 changed files with 48 additions and 1 deletions

View File

@@ -67,9 +67,10 @@ type responseWriter struct {
bufferedStr *bufio.Writer
buf []byte
headerWritten bool
contentLen int64 // if handler set valid Content-Length header
numWritten int64 // bytes written
headerWritten bool
isHead bool
}
var (
@@ -162,6 +163,10 @@ func (w *responseWriter) Write(p []byte) (int, error) {
return 0, http.ErrContentLength
}
if w.isHead {
return len(p), nil
}
df := &dataFrame{Length: uint64(len(p))}
w.buf = w.buf[:0]
w.buf = df.Append(w.buf)