Skip to content

Commit 6143a13

Browse files
neildthanm
authored andcommitted
[internal-branch.go1.18-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#56323. 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/+/457416 Reviewed-by: Than McIntosh <[email protected]>
1 parent 4205dd4 commit 6143a13

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
@@ -3474,21 +3474,6 @@ func TestConfigureServer(t *testing.T) {
34743474
}
34753475
}
34763476

3477-
func TestServerRejectHeadWithBody(t *testing.T) {
3478-
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
3479-
// No response body.
3480-
})
3481-
defer st.Close()
3482-
st.greet()
3483-
st.writeHeaders(HeadersFrameParam{
3484-
StreamID: 1, // clients send odd numbers
3485-
BlockFragment: st.encodeHeader(":method", "HEAD"),
3486-
EndStream: false, // what we're testing, a bogus HEAD request with body
3487-
EndHeaders: true,
3488-
})
3489-
st.wantRSTStream(1, ErrCodeProtocol)
3490-
}
3491-
34923477
func TestServerNoAutoContentLengthOnHead(t *testing.T) {
34933478
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
34943479
// No response body. (or smaller than one frame)

0 commit comments

Comments
 (0)