Read the full (empty) response body before closing it,
to avoid cancelling the request while the server handler
is still running.
Wrap the ResponseWriter before calling NewResponseController:
This test is intended to verify that wrapping the controller
works properly, but neglected to actually wrap the controller.
Fixes #56961.
Change-Id: I00269f897448ab34676338707b7a04d19ff17963
Reviewed-on: https://go-review.googlesource.com/c/go/+/453860
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
func TestWrappedResponseController(t *testing.T) { run(t, testWrappedResponseController) }
func testWrappedResponseController(t *testing.T, mode testMode) {
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
+ w = wrapWriter{w}
ctl := NewResponseController(w)
if err := ctl.Flush(); err != nil {
t.Errorf("ctl.Flush() = %v, want nil", err)
if err != nil {
t.Fatalf("unexpected connection error: %v", err)
}
+ io.Copy(io.Discard, res.Body)
defer res.Body.Close()
}