Merge pull request #1442 from martinbaillie/master
Pass stripped prefix downstream as header (#985)
This commit is contained in:
commit
dc01094863
1 changed files with 5 additions and 0 deletions
|
@ -5,6 +5,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
forwardedPrefixHeader = "X-Forwarded-Prefix"
|
||||
)
|
||||
|
||||
// StripPrefix is a middleware used to strip prefix from an URL request
|
||||
type StripPrefix struct {
|
||||
Handler http.Handler
|
||||
|
@ -15,6 +19,7 @@ func (s *StripPrefix) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
for _, prefix := range s.Prefixes {
|
||||
if p := strings.TrimPrefix(r.URL.Path, strings.TrimSpace(prefix)); len(p) < len(r.URL.Path) {
|
||||
r.URL.Path = p
|
||||
r.Header[forwardedPrefixHeader] = []string{prefix}
|
||||
r.RequestURI = r.URL.RequestURI()
|
||||
s.Handler.ServeHTTP(w, r)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue