fix forwarding unescaped paths
This commit is contained in:
parent
c9565782b4
commit
cd95d80497
1 changed files with 9 additions and 2 deletions
11
main.go
11
main.go
|
@ -79,10 +79,12 @@ func proxy() http.Handler {
|
|||
}
|
||||
}
|
||||
|
||||
escapedPath := r.URL.EscapedPath()
|
||||
|
||||
var pathDef pathDef
|
||||
matched := false
|
||||
for _, hostPathDef := range hd {
|
||||
if !strings.HasPrefix(r.URL.Path, hostPathDef.path) {
|
||||
if !strings.HasPrefix(escapedPath, hostPathDef.path) {
|
||||
continue
|
||||
}
|
||||
if !matched || len(hostPathDef.path) > len(pathDef.path) {
|
||||
|
@ -96,7 +98,12 @@ func proxy() http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
r.URL.Path = r.URL.Path[len(pathDef.path):]
|
||||
r.URL.RawPath = escapedPath[len(pathDef.path):]
|
||||
unescapedPath, err := url.PathUnescape(r.URL.RawPath)
|
||||
if err != nil {
|
||||
panic("unreachable")
|
||||
}
|
||||
r.URL.Path = unescapedPath
|
||||
|
||||
if pathDef.credentials != nil {
|
||||
match := false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue