diff --git a/main.go b/main.go index 373f2ed..ee05fd9 100644 --- a/main.go +++ b/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