Skip to content

Commit

Permalink
net/http: clientHeadContentLength test now in http2 mode
Browse files Browse the repository at this point in the history
Change-Id: If6cc1298ad550790ee981c1b5dc618a14947dc4a
Reviewed-on: https://go-review.googlesource.com/17526
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
odeke-em authored and bradfitz committed Dec 9, 2015
1 parent cdc6577 commit 5d7dc23
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/net/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,14 +768,22 @@ func TestHTTPSClientDetectsHTTPServer(t *testing.T) {
}

// 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)
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 != "" {
w.Header().Set("Content-Length", v)
}
}))
defer ts.Close()
defer cst.close()
tests := []struct {
suffix string
want int64
Expand All @@ -785,8 +793,8 @@ func TestClientHeadContentLength(t *testing.T) {
{"", -1},
}
for _, tt := range tests {
req, _ := NewRequest("HEAD", ts.URL+tt.suffix, nil)
res, err := DefaultClient.Do(req)
req, _ := NewRequest("HEAD", cst.ts.URL+tt.suffix, nil)
res, err := cst.c.Do(req)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 5d7dc23

Please sign in to comment.