Commit 691e63b7 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: update bundled copy of http2, enable TestTrailersServerToClient 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 #13557

Change-Id: I6261d439f6c0d17654a1a7928790e8ffed16df6c
Reviewed-on: https://go-review.googlesource.com/17931
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarBlake Mizerany <blake.mizerany@gmail.com>
parent 40ac3690
......@@ -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)
......@@ -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{
......
This diff is collapsed.
......@@ -74,6 +74,12 @@ type Response struct {
// Trailer maps trailer keys to values, in the same
// format as the header.
//
// The Trailer initially contains only the server's
// pre-declared trailer keys, but with nil values. Trailer
// must not be access concurrently with Read calls on the
// Body. After Body.Read has returned io.EOF, Trailer can be read
// again and will contain any values sent by the server.
Trailer Header
// The Request that was sent to obtain this Response.
......
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