1
0
Fork 0

Correct Entrypoint Redirect with Stripped or Added Path

This commit is contained in:
Daniel Tomcej 2018-07-31 03:28:03 -06:00 committed by Traefiker Bot
parent eea60b6baa
commit 91cafd1752
6 changed files with 222 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package middlewares
import (
"context"
"net/http"
"github.com/containous/mux"
@ -39,10 +40,13 @@ func (s *StripPrefixRegex) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
trailingSlash := r.URL.Path == prefix.Path+"/"
r.URL.Path = r.URL.Path[len(prefix.Path):]
if r.URL.RawPath != "" {
r.URL.RawPath = r.URL.RawPath[len(prefix.Path):]
}
r = r.WithContext(context.WithValue(r.Context(), StripPrefixSlashKey, trailingSlash))
r = r.WithContext(context.WithValue(r.Context(), StripPrefixKey, prefix.Path))
r.Header.Add(ForwardedPrefixHeader, prefix.Path)
r.RequestURI = r.URL.RequestURI()
s.Handler.ServeHTTP(w, r)