From 438097d76259d4670fb324c834c2426a7f1946f8 Mon Sep 17 00:00:00 2001
From: Brad Fitzpatrick
Date: Tue, 1 Dec 2015 22:16:42 +0000
Subject: [PATCH] http2: make the Transport write request body data as it's
available
Unlike HTTP/1, we now permit streaming the write of a request body as
we read the response body, since HTTP/2's framing makes it possible.
Our behavior however is based on a heuristic: we always begin writing
the request body right away (like previously, and like HTTP/1), but if
we're still writing the request body and the server replies with a
status code over 299 (not 1xx and not 2xx), then we stop writing the
request body, assuming the server doesn't care about it. There is
currently no switch (and hopefully won't be) to force enable this
behavior. In the case where the server replied with a 1xx/2xx and
we're still writing the request body but the server doesn't want it,
the server can do a RST_STREAM, which we respect as before and stop
sending.
Also in this CL:
* adds an h2demo handler at https://http2.golang.org/ECHO to demo it
* fixes a potential flow control integer truncation bug
* start of clientTester type used for the tests in this CL, similar
to the serverTester. It's still a bit cumbersome to write client
tests, though.
* fix potential deadlock where awaitFlowControl could block while
waiting a stream reset arrived. fix it by moving all checks into
the sync.Cond loop, rather than having a sync.Cond check followed
by a select. simplifies code, too.
* fix two data races in test-only code.
Updates golang/go#13444
Change-Id: Idfda6833a212a89fcd65293cdeb4169d1723724f
Reviewed-on: https://go-review.googlesource.com/17310
Reviewed-by: Blake Mizerany
---
http2/h2demo/h2demo.go | 36 +++++
http2/server_test.go | 6 +-
http2/transport.go | 98 ++++++++-----
http2/transport_test.go | 303 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 406 insertions(+), 37 deletions(-)
diff --git a/http2/h2demo/h2demo.go b/http2/h2demo/h2demo.go
index 8d5e4fd1c..15ef52f9b 100644
--- a/http2/h2demo/h2demo.go
+++ b/http2/h2demo/h2demo.go
@@ -91,6 +91,7 @@ href="https://golang.org/issues">file a bug.
GET /redirect to redirect back to / (this page)
GET /goroutines to see all active goroutines in this server
PUT something to /crc32 to get a count of number of bytes and its CRC-32
+ PUT something to /ECHO and it will be streamed back to you capitalized