httpserver: Base path of "/" matches all paths, even empty ones

Fixes #1645
This commit is contained in:
Matthew Holt
2017-05-02 09:43:43 -06:00
parent 9fbac10a4b
commit 5e467883b8
3 changed files with 74 additions and 7 deletions

View File

@@ -5,19 +5,25 @@ import (
"strings"
)
// Path represents a URI path.
// Path represents a URI path. It should usually be
// set to the value of a request path.
type Path string
// Matches checks to see if other matches p.
// Matches checks to see if base matches p. The correct
// usage of this method sets p as the request path, and
// base as a Caddyfile (user-defined) rule path.
//
// Path matching will probably not always be a direct
// comparison; this method assures that paths can be
// easily and consistently matched.
func (p Path) Matches(other string) bool {
if CaseSensitivePath {
return strings.HasPrefix(string(p), other)
func (p Path) Matches(base string) bool {
if base == "/" {
return true
}
return strings.HasPrefix(strings.ToLower(string(p)), strings.ToLower(other))
if CaseSensitivePath {
return strings.HasPrefix(string(p), base)
}
return strings.HasPrefix(strings.ToLower(string(p)), strings.ToLower(base))
}
// PathMatcher is a Path RequestMatcher.