]> Cypherpunks repositories - gostls13.git/commit
net/http/httputil: add ReverseProxy.Rewrite
authorDamien Neil <dneil@google.com>
Wed, 18 May 2022 23:23:28 +0000 (16:23 -0700)
committerDamien Neil <dneil@google.com>
Tue, 16 Aug 2022 20:01:36 +0000 (20:01 +0000)
commita55793835f16d0242be18aff4ec0bd13494175bd
treed176c1b120a56875f1f33cf2c0b81f91f0084ff4
parent68005592b38027490a08972f13269406b2556a07
net/http/httputil: add ReverseProxy.Rewrite

Add a new Rewrite hook to ReverseProxy, superseding the Director hook.

Director does not distinguish between the inbound and outbound request,
which makes it possible for headers added by Director to be inadvertently
removed before forwarding if they are listed in the inbound request's
Connection header. Rewrite accepts a value containing the inbound
and outbound requests, with hop-by-hop headers already removed from
the outbound request, avoiding this problem.

ReverseProxy's appends the client IP to the inbound X-Forwarded-For
header by default. Users must manually delete untrusted X-Forwarded-For
values. When used with a Rewrite hook, ReverseProxy now strips
X-Forwarded-* headers by default.

NewSingleHostReverseProxy creates a proxy that does not rewrite the
Host header of inbound requests. Changing this behavior is
cumbersome, as it requires wrapping the Director function created
by NewSingleHostReverseProxy. The Rewrite hook's ProxyRequest
parameter provides a SetURL method that provides equivalent
functionality to NewSingleHostReverseProxy, rewrites the Host
header by default, and can be more easily extended with additional
customizations.

Fixes #28168.
Fixes #50580.
Fixes #53002.

Change-Id: Ib84e2fdd1d52c610e3887af66f517d4a74e594d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/407214
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
api/next/53002.txt [new file with mode: 0644]
src/net/http/httputil/example_test.go
src/net/http/httputil/reverseproxy.go
src/net/http/httputil/reverseproxy_test.go