added path replacement rule

This commit is contained in:
ssttevee 2017-04-25 11:13:39 -07:00
parent 5a8215a1e4
commit aa8375e82b
5 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,20 @@
package middlewares
import (
"net/http"
)
// ReplacePath is a middleware used to replace the path of a URL request
type ReplacePath struct {
Handler http.Handler
Path string
}
// ReplacedPathHeader is the default header to set the old path to
const ReplacedPathHeader = "X-Replaced-Path"
func (s *ReplacePath) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.Header.Add(ReplacedPathHeader, r.URL.Path)
r.URL.Path = s.Path
s.Handler.ServeHTTP(w, r)
}