From 7631116ff52c37c863e7938b74633a87f294d631 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Thu, 28 Apr 2016 12:28:44 +0100 Subject: [PATCH] Add explicity PathReplace middleware (#1393) --- common/middleware/path_rewrite.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/middleware/path_rewrite.go b/common/middleware/path_rewrite.go index c19b4faec..195a779ab 100644 --- a/common/middleware/path_rewrite.go +++ b/common/middleware/path_rewrite.go @@ -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) + }) +}