Skip to content

Commit 3d3d6eb

Browse files
committed
net/http: update bundled http2 and add tests for two fixed issues
Updates to http2's golang.org/cl/17590 (git rev 1796f9b8b) Fixes #13495 Fixes #13532 Change-Id: I9b95ab438e1d895c75d031d8fcf2605921182a5e Reviewed-on: https://go-review.googlesource.com/17591 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]>
1 parent 1092257 commit 3d3d6eb

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

src/net/http/clientserver_test.go

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ func testChunkedResponseHeaders(t *testing.T, h2 bool) {
121121
}
122122
}
123123

124+
type reqFunc func(c *Client, url string) (*Response, error)
125+
124126
// h12Compare is a test that compares HTTP/1 and HTTP/2 behavior
125127
// against each other.
126128
type h12Compare struct {
127-
Handler func(ResponseWriter, *Request) // required
128-
ReqFunc func(c *Client, url string) (*Response, error) // optional
129-
CheckResponse func(proto string, res *Response) // optional
129+
Handler func(ResponseWriter, *Request) // required
130+
ReqFunc reqFunc // optional
131+
CheckResponse func(proto string, res *Response) // optional
130132
}
131133

132-
func (tt h12Compare) reqFunc() func(c *Client, url string) (*Response, error) {
134+
func (tt h12Compare) reqFunc() reqFunc {
133135
if tt.ReqFunc == nil {
134136
return (*Client).Get
135137
}
@@ -213,6 +215,36 @@ func (tt h12Compare) normalizeRes(t *testing.T, res *Response, wantProto string)
213215
}
214216
}
215217

218+
// Issue 13532
219+
func TestH12_HeadContentLengthNoBody(t *testing.T) {
220+
h12Compare{
221+
ReqFunc: (*Client).Head,
222+
Handler: func(w ResponseWriter, r *Request) {
223+
},
224+
}.run(t)
225+
}
226+
227+
func TestH12_HeadContentLengthSmallBody(t *testing.T) {
228+
h12Compare{
229+
ReqFunc: (*Client).Head,
230+
Handler: func(w ResponseWriter, r *Request) {
231+
io.WriteString(w, "small")
232+
},
233+
}.run(t)
234+
}
235+
236+
func TestH12_HeadContentLengthLargeBody(t *testing.T) {
237+
h12Compare{
238+
ReqFunc: (*Client).Head,
239+
Handler: func(w ResponseWriter, r *Request) {
240+
chunk := strings.Repeat("x", 512<<10)
241+
for i := 0; i < 10; i++ {
242+
io.WriteString(w, chunk)
243+
}
244+
},
245+
}.run(t)
246+
}
247+
216248
func TestH12_200NoBody(t *testing.T) {
217249
h12Compare{Handler: func(w ResponseWriter, r *Request) {}}.run(t)
218250
}
@@ -371,3 +403,12 @@ func test304Responses(t *testing.T, h2 bool) {
371403
t.Errorf("got unexpected body %q", string(body))
372404
}
373405
}
406+
407+
func TestH12_ServerEmptyContentLength(t *testing.T) {
408+
h12Compare{
409+
Handler: func(w ResponseWriter, r *Request) {
410+
w.Header()["Content-Type"] = []string{""}
411+
io.WriteString(w, "<html><body>hi</body></html>")
412+
},
413+
}.run(t)
414+
}

src/net/http/h2_bundle.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)