Skip to content

Commit

Permalink
net/http: update bundled copy of http2, enable TestTrailersServerToCl…
Browse files Browse the repository at this point in the history
…ient tests

This CL updates the bundled copy of x/net/http2 to include
https://golang.org/cl/17930 and enables the previously-skipped tests
TestTrailersServerToClient_h2 and TestTrailersServerToClient_Flush_h2.

It also updates the docs on http.Response.Trailer to describe how to
use it. No change in rules. Just documenting the old unwritten rules.
(there were tests locking in the behavior, and misc docs and examples
scattered about, but not on http.Response.Trailer itself)

Updates golang#13557

Change-Id: I6261d439f6c0d17654a1a7928790e8ffed16df6c
Reviewed-on: https://go-review.googlesource.com/17931
Run-TryBot: Brad Fitzpatrick <[email protected]>
Reviewed-by: Blake Mizerany <[email protected]>
  • Loading branch information
bradfitz committed Dec 17, 2015
1 parent 40ac369 commit 691e63b
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 46 deletions.
35 changes: 22 additions & 13 deletions src/net/http/clientserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,10 @@ func testTrailersClientToServer(t *testing.T, h2 bool) {
}

// Tests that servers send trailers to a client and that the client can read them.
func TestTrailersServerToClient_h1(t *testing.T) { testTrailersServerToClient(t, h1Mode, false) }
func TestTrailersServerToClient_h2(t *testing.T) {
t.Skip("skipping in http2 mode; golang.org/issue/13557")
testTrailersServerToClient(t, h2Mode, false)
}
func TestTrailersServerToClient_h1(t *testing.T) { testTrailersServerToClient(t, h1Mode, false) }
func TestTrailersServerToClient_h2(t *testing.T) { testTrailersServerToClient(t, h2Mode, false) }
func TestTrailersServerToClient_Flush_h1(t *testing.T) { testTrailersServerToClient(t, h1Mode, true) }
func TestTrailersServerToClient_Flush_h2(t *testing.T) {
t.Skip("skipping in http2 mode; golang.org/issue/13557")
testTrailersServerToClient(t, h2Mode, true)
}
func TestTrailersServerToClient_Flush_h2(t *testing.T) { testTrailersServerToClient(t, h2Mode, true) }

func testTrailersServerToClient(t *testing.T, h2, flush bool) {
defer afterTest(t)
Expand Down Expand Up @@ -564,11 +558,26 @@ func testTrailersServerToClient(t *testing.T, h2, flush bool) {
t.Fatal(err)
}

delete(res.Header, "Date") // irrelevant for test
if got, want := res.Header, (Header{
wantHeader := Header{
"Content-Type": {"text/plain; charset=utf-8"},
}); !reflect.DeepEqual(got, want) {
t.Errorf("Header = %v; want %v", got, want)
}
wantLen := -1
if h2 && !flush {
// In HTTP/1.1, any use of trailers forces HTTP/1.1
// chunking and a flush at the first write. That's
// unnecessary with HTTP/2's framing, so the server
// is able to calculate the length while still sending
// trailers afterwards.
wantLen = len(body)
wantHeader["Content-Length"] = []string{fmt.Sprint(wantLen)}
}
if res.ContentLength != int64(wantLen) {
t.Errorf("ContentLength = %v; want %v", res.ContentLength, wantLen)
}

delete(res.Header, "Date") // irrelevant for test
if !reflect.DeepEqual(res.Header, wantHeader) {
t.Errorf("Header = %v; want %v", res.Header, wantHeader)
}

if got, want := res.Trailer, (Header{
Expand Down
208 changes: 175 additions & 33 deletions src/net/http/h2_bundle.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 691e63b

Please sign in to comment.