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:
committed by
Ralf Haferkamp
parent
de4529d6b2
commit
07a718dc8e
@@ -1,9 +1,11 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
@@ -146,10 +148,14 @@ func TestRouter(t *testing.T) {
|
||||
t.Errorf("TestRouter route flag unprotected expected to be %t got %t", test.unprotected, routingInfo.IsRouteUnprotected())
|
||||
}
|
||||
|
||||
routingInfo.Director()(r)
|
||||
pr := &httputil.ProxyRequest{
|
||||
In: r,
|
||||
Out: r.Clone(context.Background()),
|
||||
}
|
||||
routingInfo.Rewrite()(pr)
|
||||
|
||||
if r.URL.Host != test.target {
|
||||
t.Errorf("TestRouter got host %s expected %s", r.URL.Host, test.target)
|
||||
if pr.Out.URL.Host != test.target {
|
||||
t.Errorf("TestRouter got host %s expected %s", pr.Out.URL.Host, test.target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user