1
0
Fork 0

enable prefix matching within slash boundaries

This commit is contained in:
Marco Jantke 2017-10-06 11:34:03 +02:00 committed by Traefiker
parent 5a578c5375
commit fd70e6edb1
2 changed files with 9 additions and 9 deletions

View file

@ -16,17 +16,9 @@ type StripPrefix struct {
func (s *StripPrefix) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for _, prefix := range s.Prefixes {
origPrefix := strings.TrimSpace(prefix)
if origPrefix == r.URL.Path {
r.URL.Path = "/"
s.serveRequest(w, r, origPrefix)
return
}
prefix = strings.TrimSuffix(origPrefix, "/") + "/"
if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) {
r.URL.Path = "/" + strings.TrimPrefix(p, "/")
s.serveRequest(w, r, origPrefix)
s.serveRequest(w, r, strings.TrimSpace(prefix))
return
}
}