summaryrefslogtreecommitdiffhomepage
path: root/caddyhttp
diff options
context:
space:
mode:
authorTw <[email protected]>2016-10-11 17:06:49 +0800
committerTw <[email protected]>2016-10-11 17:06:59 +0800
commit4baca884c5e4767b114f3d363188e6570a24e90d (patch)
tree1c5ed876b9ad3ec018014b9c86dc2fefe68bf0b1 /caddyhttp
parent9ced4b17e56e7ea260dcdd11657a09c09e6f2406 (diff)
downloadcaddy-4baca884c5e4767b114f3d363188e6570a24e90d.tar.gz
caddy-4baca884c5e4767b114f3d363188e6570a24e90d.zip
proxy: preserve path trailing slash if it was there
fix issue #1177 Signed-off-by: Tw <[email protected]>
Diffstat (limited to 'caddyhttp')
-rw-r--r--caddyhttp/proxy/proxy_test.go5
-rw-r--r--caddyhttp/proxy/reverseproxy.go6
2 files changed, 11 insertions, 0 deletions
diff --git a/caddyhttp/proxy/proxy_test.go b/caddyhttp/proxy/proxy_test.go
index be55ff566..ccdb068bb 100644
--- a/caddyhttp/proxy/proxy_test.go
+++ b/caddyhttp/proxy/proxy_test.go
@@ -791,6 +791,11 @@ func TestProxyDirectorURL(t *testing.T) {
expectURL: `https://localhost:2021/t?foo%3dbar&t%3dw`,
without: "/test",
},
+ {
+ requestURL: `http://localhost:2020/test/`,
+ targetURL: `https://localhost:2021/t/`,
+ expectURL: `https://localhost:2021/t/test/`,
+ },
} {
targetURL, err := url.Parse(c.targetURL)
if err != nil {
diff --git a/caddyhttp/proxy/reverseproxy.go b/caddyhttp/proxy/reverseproxy.go
index 1374c08ff..c537f7c98 100644
--- a/caddyhttp/proxy/reverseproxy.go
+++ b/caddyhttp/proxy/reverseproxy.go
@@ -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)
+ // 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.
// This is done because req.URL passed to your proxied service
// will have the full path of the socket file prefixed to it.