summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-02-15 12:00:02 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2019-02-15 12:00:02 -0700
commitc1d6c928e3a29e94013bda4d339d9e426500c8e7 (patch)
tree4c9cf9f4e841423eb4ceefc59c33be1affa13975
parent118f66670690b49a37c2c7a3df1dc22ca281279d (diff)
parente9641c5c7e3534b74f5817407456e14969da0fae (diff)
Merge branch 'master' of ssh://github.com/mholt/caddyv0.11.4
-rw-r--r--caddyhttp/proxy/upstream.go12
-rw-r--r--caddyhttp/proxy/upstream_test.go4
2 files changed, 14 insertions, 2 deletions
diff --git a/caddyhttp/proxy/upstream.go b/caddyhttp/proxy/upstream.go
index a89fdfb0..8dac144e 100644
--- a/caddyhttp/proxy/upstream.go
+++ b/caddyhttp/proxy/upstream.go
@@ -665,7 +665,17 @@ func (u *staticUpstream) Select(r *http.Request) *UpstreamHost {
func (u *staticUpstream) AllowedPath(requestPath string) bool {
for _, ignoredSubPath := range u.IgnoredSubPaths {
- if httpserver.Path(path.Clean(requestPath)).Matches(path.Join(u.From(), ignoredSubPath)) {
+ p := path.Clean(requestPath)
+ e := path.Join(u.From(), ignoredSubPath)
+ // Re-add a trailing slashes if the original
+ // paths had one and the cleaned paths don't
+ if strings.HasSuffix(requestPath, "/") && !strings.HasSuffix(p, "/") {
+ p = p + "/"
+ }
+ if strings.HasSuffix(ignoredSubPath, "/") && !strings.HasSuffix(e, "/") {
+ e = e + "/"
+ }
+ if httpserver.Path(p).Matches(e) {
return false
}
}
diff --git a/caddyhttp/proxy/upstream_test.go b/caddyhttp/proxy/upstream_test.go
index 2c72f97a..2e10eb09 100644
--- a/caddyhttp/proxy/upstream_test.go
+++ b/caddyhttp/proxy/upstream_test.go
@@ -136,7 +136,7 @@ func TestRegisterPolicy(t *testing.T) {
func TestAllowedPaths(t *testing.T) {
upstream := &staticUpstream{
from: "/proxy",
- IgnoredSubPaths: []string{"/download", "/static"},
+ IgnoredSubPaths: []string{"/download", "/static", "/trailingslash/"},
}
tests := []struct {
url string
@@ -153,6 +153,8 @@ func TestAllowedPaths(t *testing.T) {
{"/proxy//static", false},
{"/proxy//static//download", false},
{"/proxy//download", false},
+ {"/proxy/trailingslash", true},
+ {"/proxy/trailingslash/", false},
}
for i, test := range tests {