Skip to content

Commit 183621a

Browse files
neildthanm
authored andcommitted
[internal-branch.go1.19-vendor] http2: accept HEAD requests with a body
RFC 7231 permits HEAD requests to contain a body, although it does state there are no defined semantics for payloads of HEAD requests and that some servers may reject HEAD requests with a payload. Accept HEAD requests with a body. Test is in net/http CL 418614. For golang/go#53960. For golang/go#56154. Change-Id: I946d3ec796054c3908beb8a69cc78aa51c04c972 Reviewed-on: https://go-review.googlesource.com/c/net/+/418634 Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Cherry Mui <[email protected]> (cherry picked from commit f8f703f) Reviewed-on: https://go-review.googlesource.com/c/net/+/457357 Reviewed-by: Than McIntosh <[email protected]>
1 parent aa7e2cc commit 183621a

File tree

2 files changed

+1
-21
lines changed

2 files changed

+1
-21
lines changed

http2/server.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,12 +2040,6 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
20402040
return nil, nil, sc.countError("bad_path_method", streamError(f.StreamID, ErrCodeProtocol))
20412041
}
20422042

2043-
bodyOpen := !f.StreamEnded()
2044-
if rp.method == "HEAD" && bodyOpen {
2045-
// HEAD requests can't have bodies
2046-
return nil, nil, sc.countError("head_body", streamError(f.StreamID, ErrCodeProtocol))
2047-
}
2048-
20492043
rp.header = make(http.Header)
20502044
for _, hf := range f.RegularFields() {
20512045
rp.header.Add(sc.canonicalHeader(hf.Name), hf.Value)
@@ -2058,6 +2052,7 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
20582052
if err != nil {
20592053
return nil, nil, err
20602054
}
2055+
bodyOpen := !f.StreamEnded()
20612056
if bodyOpen {
20622057
if vv, ok := rp.header["Content-Length"]; ok {
20632058
if cl, err := strconv.ParseUint(vv[0], 10, 63); err == nil {

http2/server_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,21 +3455,6 @@ func TestConfigureServer(t *testing.T) {
34553455
}
34563456
}
34573457

3458-
func TestServerRejectHeadWithBody(t *testing.T) {
3459-
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
3460-
// No response body.
3461-
})
3462-
defer st.Close()
3463-
st.greet()
3464-
st.writeHeaders(HeadersFrameParam{
3465-
StreamID: 1, // clients send odd numbers
3466-
BlockFragment: st.encodeHeader(":method", "HEAD"),
3467-
EndStream: false, // what we're testing, a bogus HEAD request with body
3468-
EndHeaders: true,
3469-
})
3470-
st.wantRSTStream(1, ErrCodeProtocol)
3471-
}
3472-
34733458
func TestServerNoAutoContentLengthOnHead(t *testing.T) {
34743459
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
34753460
// No response body. (or smaller than one frame)

0 commit comments

Comments
 (0)