summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers.go
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2019-09-09 21:46:21 -0600
committerGitHub <noreply@github.com>2019-09-09 21:46:21 -0600
commit44b7ce98505ab8a34f6c632e661dd2cfae475a17 (patch)
tree4cd125e485047419fd19098007280b013906a0bc /modules/caddyhttp/matchers.go
parent9169cd43d49236c69d5c9b7c556cb0ac0c9ce497 (diff)
parentb4f4fcd437c2f9816f9511217bde703679808679 (diff)
Merge pull request #2737 from caddyserver/fastcgi (reverse proxy!)
v2: Refactor reverse proxy and add FastCGI support
Diffstat (limited to 'modules/caddyhttp/matchers.go')
-rw-r--r--modules/caddyhttp/matchers.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 0dac151..4d0eea5 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -22,7 +22,6 @@ import (
"net/http"
"net/textproto"
"net/url"
- "path"
"path/filepath"
"regexp"
"strings"
@@ -151,12 +150,13 @@ func (MatchPath) CaddyModule() caddy.ModuleInfo {
// Match returns true if r matches m.
func (m MatchPath) Match(r *http.Request) bool {
for _, matchPath := range m {
- compare := r.URL.Path
+ // as a special case, if the first character is a
+ // wildcard, treat it as a quick suffix match
if strings.HasPrefix(matchPath, "*") {
- compare = path.Base(compare)
+ return strings.HasSuffix(r.URL.Path, matchPath[1:])
}
// can ignore error here because we can't handle it anyway
- matches, _ := filepath.Match(matchPath, compare)
+ matches, _ := filepath.Match(matchPath, r.URL.Path)
if matches {
return true
}
@@ -271,8 +271,13 @@ func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// Match returns true if r matches m.
func (m MatchHeader) Match(r *http.Request) bool {
for field, allowedFieldVals := range m {
+ actualFieldVals, fieldExists := r.Header[textproto.CanonicalMIMEHeaderKey(field)]
+ if allowedFieldVals != nil && len(allowedFieldVals) == 0 && fieldExists {
+ // a non-nil but empty list of allowed values means
+ // match if the header field exists at all
+ continue
+ }
var match bool
- actualFieldVals := r.Header[textproto.CanonicalMIMEHeaderKey(field)]
fieldVals:
for _, actualFieldVal := range actualFieldVals {
for _, allowedFieldVal := range allowedFieldVals {
@@ -616,10 +621,7 @@ func (rm ResponseMatcher) matchStatusCode(statusCode int) bool {
return true
}
for _, code := range rm.StatusCode {
- if statusCode == code {
- return true
- }
- if code < 100 && statusCode >= code*100 && statusCode < (code+1)*100 {
+ if StatusCodeMatches(statusCode, code) {
return true
}
}
@@ -628,8 +630,13 @@ func (rm ResponseMatcher) matchStatusCode(statusCode int) bool {
func (rm ResponseMatcher) matchHeaders(hdr http.Header) bool {
for field, allowedFieldVals := range rm.Headers {
+ actualFieldVals, fieldExists := hdr[textproto.CanonicalMIMEHeaderKey(field)]
+ if allowedFieldVals != nil && len(allowedFieldVals) == 0 && fieldExists {
+ // a non-nil but empty list of allowed values means
+ // match if the header field exists at all
+ continue
+ }
var match bool
- actualFieldVals := hdr[textproto.CanonicalMIMEHeaderKey(field)]
fieldVals:
for _, actualFieldVal := range actualFieldVals {
for _, allowedFieldVal := range allowedFieldVals {