зеркало из https://github.com/golang/net.git
[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 <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
(cherry picked from commit f8f703f979
)
Reviewed-on: https://go-review.googlesource.com/c/net/+/457416
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Родитель
4205dd41f8
Коммит
6143a133e5
|
@ -2040,12 +2040,6 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
|
|||
return nil, nil, sc.countError("bad_path_method", streamError(f.StreamID, ErrCodeProtocol))
|
||||
}
|
||||
|
||||
bodyOpen := !f.StreamEnded()
|
||||
if rp.method == "HEAD" && bodyOpen {
|
||||
// HEAD requests can't have bodies
|
||||
return nil, nil, sc.countError("head_body", streamError(f.StreamID, ErrCodeProtocol))
|
||||
}
|
||||
|
||||
rp.header = make(http.Header)
|
||||
for _, hf := range f.RegularFields() {
|
||||
rp.header.Add(sc.canonicalHeader(hf.Name), hf.Value)
|
||||
|
@ -2058,6 +2052,7 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
bodyOpen := !f.StreamEnded()
|
||||
if bodyOpen {
|
||||
if vv, ok := rp.header["Content-Length"]; ok {
|
||||
if cl, err := strconv.ParseUint(vv[0], 10, 63); err == nil {
|
||||
|
|
|
@ -3474,21 +3474,6 @@ func TestConfigureServer(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServerRejectHeadWithBody(t *testing.T) {
|
||||
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
// No response body.
|
||||
})
|
||||
defer st.Close()
|
||||
st.greet()
|
||||
st.writeHeaders(HeadersFrameParam{
|
||||
StreamID: 1, // clients send odd numbers
|
||||
BlockFragment: st.encodeHeader(":method", "HEAD"),
|
||||
EndStream: false, // what we're testing, a bogus HEAD request with body
|
||||
EndHeaders: true,
|
||||
})
|
||||
st.wantRSTStream(1, ErrCodeProtocol)
|
||||
}
|
||||
|
||||
func TestServerNoAutoContentLengthOnHead(t *testing.T) {
|
||||
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
// No response body. (or smaller than one frame)
|
||||
|
|
Загрузка…
Ссылка в новой задаче