From fa683fa7e479e5a7fc1266e3625e025e2a6538e7 Mon Sep 17 00:00:00 2001 From: Martin Baillie Date: Sun, 16 Apr 2017 19:24:26 +1000 Subject: [PATCH] Pass stripped prefix downstream as header --- middlewares/stripPrefix.go | 5 +++++ 1 file changed, 5 insertions(+) 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