diff options
author | Filippo Valsorda <filippo@golang.org> | 2021-08-09 12:37:04 -0400 |
---|---|---|
committer | Filippo Valsorda <filippo@golang.org> | 2021-08-09 12:37:04 -0400 |
commit | dd96ded6c86b8a38f49fa087b758455243a0f08c (patch) | |
tree | f1a70c0194af60202025ad135d1ee903e20896c3 /src/net/http/httputil/reverseproxy.go | |
parent | ddf078e08dc61f38e26f9969dd2a2151a8c73904 (diff) | |
parent | acbe242f8a2cae8ef4749806291a37d23089b572 (diff) | |
download | go-dd96ded6c86b8a38f49fa087b758455243a0f08c.tar.gz go-dd96ded6c86b8a38f49fa087b758455243a0f08c.zip |
[dev.boringcrypto.go1.15] all: merge go1.15.15 into dev.boringcrypto.go1.15dev.boringcrypto.go1.15
Change-Id: I3b20c90322a0c0deec68a161b8fcbab9188fb6b2
Diffstat (limited to 'src/net/http/httputil/reverseproxy.go')
-rw-r--r-- | src/net/http/httputil/reverseproxy.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go index f49cefbb4f..68754cb088 100644 --- a/src/net/http/httputil/reverseproxy.go +++ b/src/net/http/httputil/reverseproxy.go @@ -234,6 +234,15 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { if req.ContentLength == 0 { outreq.Body = nil // Issue 16036: nil Body for http.Transport retries } + if outreq.Body != nil { + // Reading from the request body after returning from a handler is not + // allowed, and the RoundTrip goroutine that reads the Body can outlive + // this handler. This can lead to a crash if the handler panics (see + // Issue 46866). Although calling Close doesn't guarantee there isn't + // any Read in flight after the handle returns, in practice it's safe to + // read after closing it. + defer outreq.Body.Close() + } if outreq.Header == nil { outreq.Header = make(http.Header) // Issue 33142: historical behavior was to always allocate } |