providers/proxy: don't include hostname and scheme in redirect when we only got a path and not a full URL

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-01-27 18:23:08 +01:00
parent ebb5711c32
commit 67d550a80d
2 changed files with 7 additions and 3 deletions

View File

@ -78,8 +78,12 @@ func (a *Application) getTraefikForwardUrl(r *http.Request) (*url.URL, error) {
func (a *Application) getNginxForwardUrl(r *http.Request) (*url.URL, error) { func (a *Application) getNginxForwardUrl(r *http.Request) (*url.URL, error) {
ou := r.Header.Get("X-Original-URI") ou := r.Header.Get("X-Original-URI")
if ou != "" { if ou != "" {
u, _ := url.Parse(r.URL.String()) // Turn this full URL into a relative URL
u.Path = ou u := &url.URL{
Host: "",
Scheme: "",
Path: ou,
}
a.log.WithField("url", u.String()).Info("building forward URL from X-Original-URI") a.log.WithField("url", u.String()).Info("building forward URL from X-Original-URI")
return u, nil return u, nil
} }

View File

@ -56,7 +56,7 @@ func TestForwardHandleNginx_Single_URI(t *testing.T) {
assert.Equal(t, rr.Code, http.StatusUnauthorized) assert.Equal(t, rr.Code, http.StatusUnauthorized)
s, _ := a.sessions.Get(req, constants.SeesionName) s, _ := a.sessions.Get(req, constants.SeesionName)
assert.Equal(t, "https://foo.bar/app", s.Values[constants.SessionRedirect]) assert.Equal(t, "/app", s.Values[constants.SessionRedirect])
} }
func TestForwardHandleNginx_Single_Claims(t *testing.T) { func TestForwardHandleNginx_Single_Claims(t *testing.T) {