added path replacement rule
This commit is contained in:
parent
5a8215a1e4
commit
aa8375e82b
5 changed files with 82 additions and 0 deletions
20
middlewares/replace_path.go
Normal file
20
middlewares/replace_path.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue