diff options
Diffstat (limited to 'vendor/github.com/go-chi/chi/middleware/strip.go')
-rw-r--r-- | vendor/github.com/go-chi/chi/middleware/strip.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/vendor/github.com/go-chi/chi/middleware/strip.go b/vendor/github.com/go-chi/chi/middleware/strip.go index 2b8b1842ab..1082d713ef 100644 --- a/vendor/github.com/go-chi/chi/middleware/strip.go +++ b/vendor/github.com/go-chi/chi/middleware/strip.go @@ -14,13 +14,18 @@ func StripSlashes(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { var path string rctx := chi.RouteContext(r.Context()) - if rctx.RoutePath != "" { + if rctx != nil && rctx.RoutePath != "" { path = rctx.RoutePath } else { path = r.URL.Path } if len(path) > 1 && path[len(path)-1] == '/' { - rctx.RoutePath = path[:len(path)-1] + newPath := path[:len(path)-1] + if rctx == nil { + r.URL.Path = newPath + } else { + rctx.RoutePath = newPath + } } next.ServeHTTP(w, r) } @@ -36,7 +41,7 @@ func RedirectSlashes(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { var path string rctx := chi.RouteContext(r.Context()) - if rctx.RoutePath != "" { + if rctx != nil && rctx.RoutePath != "" { path = rctx.RoutePath } else { path = r.URL.Path @@ -47,7 +52,8 @@ func RedirectSlashes(next http.Handler) http.Handler { } else { path = path[:len(path)-1] } - http.Redirect(w, r, path, 301) + redirectUrl := fmt.Sprintf("//%s%s", r.Host, path) + http.Redirect(w, r, redirectUrl, 301) return } next.ServeHTTP(w, r) |