Skip to content

Commit 66fcf56

Browse files
committed
net/http: update bundled http2, add tests reading response Body after Close
Updates to golang.org/x/net/http2 git rev 28273ec9 for https://golang.org/cl/17937 Fixes #13648 Change-Id: I27c77524b2e4a172c5f8be08f6fbb0f2e2e4b200 Reviewed-on: https://go-review.googlesource.com/17938 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]>
1 parent 54977cd commit 66fcf56

File tree

2 files changed

+68
-18
lines changed

2 files changed

+68
-18
lines changed

src/net/http/clientserver_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,25 @@ func testTrailersServerToClient(t *testing.T, h2, flush bool) {
597597
t.Errorf("Trailer after body read = %v; want %v", got, want)
598598
}
599599
}
600+
601+
// Don't allow a Body.Read after Body.Close. Issue 13648.
602+
func TestResponseBodyReadAfterClose_h1(t *testing.T) { testResponseBodyReadAfterClose(t, h1Mode) }
603+
func TestResponseBodyReadAfterClose_h2(t *testing.T) { testResponseBodyReadAfterClose(t, h2Mode) }
604+
605+
func testResponseBodyReadAfterClose(t *testing.T, h2 bool) {
606+
defer afterTest(t)
607+
const body = "Some body"
608+
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
609+
io.WriteString(w, body)
610+
}))
611+
defer cst.close()
612+
res, err := cst.c.Get(cst.ts.URL)
613+
if err != nil {
614+
t.Fatal(err)
615+
}
616+
res.Body.Close()
617+
data, err := ioutil.ReadAll(res.Body)
618+
if len(data) != 0 || err == nil {
619+
t.Fatalf("ReadAll returned %q, %v; want error", data, err)
620+
}
621+
}

src/net/http/h2_bundle.go

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

0 commit comments

Comments
 (0)