Add explicity PathReplace middleware (#1393)

This commit is contained in:
Tom Wilkie
2016-04-28 12:28:44 +01:00
parent 661185cb70
commit 7631116ff5
+14
View File
@@ -24,3 +24,17 @@ func (p pathRewrite) Wrap(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
})
}
// PathReplace replcase Request.RequestURI with the specified string.
func PathReplace(replacement string) Interface {
return pathReplace(replacement)
}
type pathReplace string
func (p pathReplace) Wrap(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.RequestURI = string(p)
next.ServeHTTP(w, r)
})
}