mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Merge pull request #1178 from tw4452852/1177
proxy: preserve path trailing slash if it was there
This commit is contained in:
commit
d44016b937
2 changed files with 11 additions and 0 deletions
|
@ -791,6 +791,11 @@ func TestProxyDirectorURL(t *testing.T) {
|
||||||
expectURL: `https://localhost:2021/t?foo%3dbar&t%3dw`,
|
expectURL: `https://localhost:2021/t?foo%3dbar&t%3dw`,
|
||||||
without: "/test",
|
without: "/test",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
requestURL: `http://localhost:2020/test/`,
|
||||||
|
targetURL: `https://localhost:2021/t/`,
|
||||||
|
expectURL: `https://localhost:2021/t/test/`,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
targetURL, err := url.Parse(c.targetURL)
|
targetURL, err := url.Parse(c.targetURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -96,7 +96,13 @@ func NewSingleHostReverseProxy(target *url.URL, without string, keepalive int) *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hadTrailingSlash := strings.HasSuffix(req.URL.Path, "/")
|
||||||
req.URL.Path = path.Join(target.Path, req.URL.Path)
|
req.URL.Path = path.Join(target.Path, req.URL.Path)
|
||||||
|
// path.Join will strip off the last /, so put it back if it was there.
|
||||||
|
if hadTrailingSlash && !strings.HasSuffix(req.URL.Path, "/") {
|
||||||
|
req.URL.Path = req.URL.Path + "/"
|
||||||
|
}
|
||||||
|
|
||||||
// Trims the path of the socket from the URL path.
|
// Trims the path of the socket from the URL path.
|
||||||
// This is done because req.URL passed to your proxied service
|
// This is done because req.URL passed to your proxied service
|
||||||
// will have the full path of the socket file prefixed to it.
|
// will have the full path of the socket file prefixed to it.
|
||||||
|
|
Loading…
Reference in a new issue