diff --git a/middlewares/stripPrefix.go b/middlewares/stripPrefix.go index 2a13c78bb..585e60305 100644 --- a/middlewares/stripPrefix.go +++ b/middlewares/stripPrefix.go @@ -5,6 +5,10 @@ import ( "strings" ) +const ( + forwardedPrefixHeader = "X-Forwarded-Prefix" +) + // StripPrefix is a middleware used to strip prefix from an URL request type StripPrefix struct { Handler http.Handler @@ -15,6 +19,7 @@ func (s *StripPrefix) ServeHTTP(w http.ResponseWriter, r *http.Request) { for _, prefix := range s.Prefixes { if p := strings.TrimPrefix(r.URL.Path, strings.TrimSpace(prefix)); len(p) < len(r.URL.Path) { r.URL.Path = p + r.Header[forwardedPrefixHeader] = []string{prefix} r.RequestURI = r.URL.RequestURI() s.Handler.ServeHTTP(w, r) return