Commit 5d7dc23e authored by Emmanuel Odeke's avatar Emmanuel Odeke Committed by Brad Fitzpatrick

net/http: clientHeadContentLength test now in http2 mode

Change-Id: If6cc1298ad550790ee981c1b5dc618a14947dc4a
Reviewed-on: https://go-review.googlesource.com/17526
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent cdc65778
...@@ -768,14 +768,22 @@ func TestHTTPSClientDetectsHTTPServer(t *testing.T) { ...@@ -768,14 +768,22 @@ func TestHTTPSClientDetectsHTTPServer(t *testing.T) {
} }
// Verify Response.ContentLength is populated. https://golang.org/issue/4126 // Verify Response.ContentLength is populated. https://golang.org/issue/4126
func TestClientHeadContentLength(t *testing.T) { func TestClientHeadContentLength_h1(t *testing.T) {
testClientHeadContentLength(t, false)
}
func TestClientHeadContentLength_h2(t *testing.T) {
testClientHeadContentLength(t, true)
}
func testClientHeadContentLength(t *testing.T, h2 bool) {
defer afterTest(t) defer afterTest(t)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
if v := r.FormValue("cl"); v != "" { if v := r.FormValue("cl"); v != "" {
w.Header().Set("Content-Length", v) w.Header().Set("Content-Length", v)
} }
})) }))
defer ts.Close() defer cst.close()
tests := []struct { tests := []struct {
suffix string suffix string
want int64 want int64
...@@ -785,8 +793,8 @@ func TestClientHeadContentLength(t *testing.T) { ...@@ -785,8 +793,8 @@ func TestClientHeadContentLength(t *testing.T) {
{"", -1}, {"", -1},
} }
for _, tt := range tests { for _, tt := range tests {
req, _ := NewRequest("HEAD", ts.URL+tt.suffix, nil) req, _ := NewRequest("HEAD", cst.ts.URL+tt.suffix, nil)
res, err := DefaultClient.Do(req) res, err := cst.c.Do(req)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment