proxy: User ReverseProxy.Rewrite instead of Director

With Go 1.20 the "Rewrite" hook for ReverseProxy was introduced to
supersede of the "Director" hook (see:
https://github.com/golang/go/commit/a55793835f16d0242be18aff4ec0bd13494175bd)

The Rewrite hooks allows for better separation between the incoming and
outgoing request. In particular it makes it pretty easy to set the
correct X-Forwarded-* Headers on the outgoing request.
The need for using "Rewrite" came up when trying to embed
authelia. It uses the X-Forwarded-Host and X-Forwared-Proto headers to
e.g. compute the correct return values for the various endpoints in
.well-known/openid-configuration.
This commit is contained in:
Ralf Haferkamp
2023-10-16 10:31:39 +02:00
committed by Ralf Haferkamp
parent de4529d6b2
commit 07a718dc8e
3 changed files with 51 additions and 43 deletions
+3 -3
View File
@@ -36,9 +36,9 @@ func NewMultiHostReverseProxy(opts ...Option) (*MultiHostReverseProxy, error) {
config: options.Config,
}
rp.Director = func(r *http.Request) {
ri := router.ContextRoutingInfo(r.Context())
ri.Director()(r)
rp.Rewrite = func(r *httputil.ProxyRequest) {
ri := router.ContextRoutingInfo(r.In.Context())
ri.Rewrite()(r)
}
tlsConf := &tls.Config{