I have come across an issue where redirect slash middleware will drop the url query params.
I have managed to temporarily fix it with:
// RedirectSlashes is a middleware that will match request paths with a trailing
// slash and redirect to the same path, less the trailing slash.
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 != "" {
path = rctx.RoutePath
} else {
path = r.URL.Path
}
if len(path) > 1 && path[len(path)-1] == '/' {
path = fmt.Sprintf("%s?%s", path[:len(path)-1], r.URL.RawQuery)
http.Redirect(w, r, path, 301)
return
}
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
But it feels somewhat incomplete
I have come across an issue where redirect slash middleware will drop the url query params.
I have managed to temporarily fix it with:
But it feels somewhat incomplete