Skip to content

Commit

Permalink
fix: prefix handling on http router
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiresviana committed Mar 17, 2021
1 parent 9978728 commit 93a35ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion http/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ func handle(fn handleFunc, prefix string, store *storage.Storage, server *settin
}
})

return http.StripPrefix(prefix, handler)
return stripPrefix(prefix, handler)
}
2 changes: 2 additions & 0 deletions http/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit 93a35ad

Please sign in to comment.