Skip to content

Commit 691e63b

Browse files
committed
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 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]>
1 parent 40ac369 commit 691e63b

File tree

3 files changed

+203
-46
lines changed

3 files changed

+203
-46
lines changed

src/net/http/clientserver_test.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,10 @@ func testTrailersClientToServer(t *testing.T, h2 bool) {
526526
}
527527

528528
// Tests that servers send trailers to a client and that the client can read them.
529-
func TestTrailersServerToClient_h1(t *testing.T) { testTrailersServerToClient(t, h1Mode, false) }
530-
func TestTrailersServerToClient_h2(t *testing.T) {
531-
t.Skip("skipping in http2 mode; golang.org/issue/13557")
532-
testTrailersServerToClient(t, h2Mode, false)
533-
}
529+
func TestTrailersServerToClient_h1(t *testing.T) { testTrailersServerToClient(t, h1Mode, false) }
530+
func TestTrailersServerToClient_h2(t *testing.T) { testTrailersServerToClient(t, h2Mode, false) }
534531
func TestTrailersServerToClient_Flush_h1(t *testing.T) { testTrailersServerToClient(t, h1Mode, true) }
535-
func TestTrailersServerToClient_Flush_h2(t *testing.T) {
536-
t.Skip("skipping in http2 mode; golang.org/issue/13557")
537-
testTrailersServerToClient(t, h2Mode, true)
538-
}
532+
func TestTrailersServerToClient_Flush_h2(t *testing.T) { testTrailersServerToClient(t, h2Mode, true) }
539533

540534
func testTrailersServerToClient(t *testing.T, h2, flush bool) {
541535
defer afterTest(t)
@@ -564,11 +558,26 @@ func testTrailersServerToClient(t *testing.T, h2, flush bool) {
564558
t.Fatal(err)
565559
}
566560

567-
delete(res.Header, "Date") // irrelevant for test
568-
if got, want := res.Header, (Header{
561+
wantHeader := Header{
569562
"Content-Type": {"text/plain; charset=utf-8"},
570-
}); !reflect.DeepEqual(got, want) {
571-
t.Errorf("Header = %v; want %v", got, want)
563+
}
564+
wantLen := -1
565+
if h2 && !flush {
566+
// In HTTP/1.1, any use of trailers forces HTTP/1.1
567+
// chunking and a flush at the first write. That's
568+
// unnecessary with HTTP/2's framing, so the server
569+
// is able to calculate the length while still sending
570+
// trailers afterwards.
571+
wantLen = len(body)
572+
wantHeader["Content-Length"] = []string{fmt.Sprint(wantLen)}
573+
}
574+
if res.ContentLength != int64(wantLen) {
575+
t.Errorf("ContentLength = %v; want %v", res.ContentLength, wantLen)
576+
}
577+
578+
delete(res.Header, "Date") // irrelevant for test
579+
if !reflect.DeepEqual(res.Header, wantHeader) {
580+
t.Errorf("Header = %v; want %v", res.Header, wantHeader)
572581
}
573582

574583
if got, want := res.Trailer, (Header{

src/net/http/h2_bundle.go

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

0 commit comments

Comments
 (0)