diff options
author | Damien Neil <dneil@google.com> | 2020-06-11 13:30:23 -0700 |
---|---|---|
committer | Andrew Bonventre <andybons@golang.org> | 2020-06-17 19:48:45 +0000 |
commit | 8b98498a5833111402a2fe8f13a6605e071994b6 (patch) | |
tree | ac57a9815197a6e5777df35f53a969356e3b7c60 | |
parent | f84bbd52b0021c401b0b6508e90e913ae0aa241d (diff) | |
download | go-git-8b98498a5833111402a2fe8f13a6605e071994b6.tar.gz |
net/http: make Transport.RoundTrip preserve Requests
Ensure that the exact Request passed to Transport.RoundTrip
is returned in the Response. Do not replace the Request with
a copy when resetting the request body.
Fixes #39533
Change-Id: Ie6fb080c24b0f6625b0761b7aa542af3d2411817
Reviewed-on: https://go-review.googlesource.com/c/go/+/237560
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
-rw-r--r-- | src/net/http/transport.go | 2 | ||||
-rw-r--r-- | src/net/http/transport_test.go | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/net/http/transport.go b/src/net/http/transport.go index da86b26106..a41e732d98 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -511,6 +511,7 @@ func (t *Transport) roundTrip(req *Request) (*Response, error) { } } + origReq := req req = setupRewindBody(req) if altRT := t.alternateRoundTripper(req); altRT != nil { @@ -572,6 +573,7 @@ func (t *Transport) roundTrip(req *Request) (*Response, error) { resp, err = pconn.roundTrip(treq) } if err == nil { + resp.Request = origReq return resp, nil } diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 99056a42d9..31a41f5351 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -3511,7 +3511,8 @@ func TestRetryRequestsOnError(t *testing.T) { for i := 0; i < 3; i++ { t0 := time.Now() - res, err := c.Do(tc.req()) + req := tc.req() + res, err := c.Do(req) if err != nil { if time.Since(t0) < MaxWriteWaitBeforeConnReuse/2 { mu.Lock() @@ -3522,6 +3523,9 @@ func TestRetryRequestsOnError(t *testing.T) { t.Skipf("connection likely wasn't recycled within %d, interfering with actual test; skipping", MaxWriteWaitBeforeConnReuse) } res.Body.Close() + if res.Request != req { + t.Errorf("Response.Request != original request; want identical Request") + } } mu.Lock() |