]> Cypherpunks repositories - gostls13.git/commit
net/http/httputil: wrap ReverseProxy's outbound request body so Close is a noop
authorNicholas S. Husin <nsh@golang.org>
Wed, 19 Nov 2025 22:10:02 +0000 (17:10 -0500)
committerNicholas Husin <nsh@golang.org>
Thu, 20 Nov 2025 23:15:20 +0000 (15:15 -0800)
commit3ad2e113fc3dd202bfb2ef87d376b6ef54337f0b
treeca195f59e220f61bf6f73f2a7164b8c3363f4da1
parentd58b733646d2d52638b08d5c44afbc7292aeca4d
net/http/httputil: wrap ReverseProxy's outbound request body so Close is a noop

Within ReverseProxy, we are currently sending a clone of our inbound
request (from client) as our outbound request (to upstream). However,
the clone of the request has a shallow copy of the request body. As a
result, when the outbound request body is closed, the inbound request
body (i.e. the outbound request body of the client) will also be closed.

This causes an unfortunate effect where we would infinitely hang when a
client sends a request with a 100-continue header via a ReverseProxy,
but the ReverseProxy fails to make a connection to the upstream server.

When this happens, the ReverseProxy's outbound request body would be
closed, which in turns also closes the client's request body.
Internally, when we close a request body, we would try to consume and
discard the content. Since the client has yet to actually send the body
content (due to 100-continue header) though, an infinite hang occurs.

To prevent this, we make sure that closing an outbound request body from
a ReverseProxy is a noop.

For #75933

Change-Id: I52dc7247f689f35a6e93d1f32b2d003d90e9d2c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/722160
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/net/http/httputil/reverseproxy.go
src/net/http/httputil/reverseproxy_test.go