fix: prefix handling on http router

This commit is contained in:
Ramires Viana 2021-03-17 17:54:25 +00:00
parent 99787287bb
commit 93a35ad251
2 changed files with 3 additions and 1 deletions

View File

@ -73,5 +73,5 @@ func handle(fn handleFunc, prefix string, store *storage.Storage, server *settin
}
})
return http.StripPrefix(prefix, handler)
return stripPrefix(prefix, handler)
}

View File

@ -56,11 +56,13 @@ func stripPrefix(prefix string, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
p := strings.TrimPrefix(r.URL.Path, prefix)
rp := strings.TrimPrefix(r.URL.RawPath, prefix)
r2 := new(http.Request)
*r2 = *r
r2.URL = new(url.URL)
*r2.URL = *r.URL
r2.URL.Path = p
r2.URL.RawPath = rp
h.ServeHTTP(w, r2)
})
}