From 026df7c5cb33331d223afc6a9599274e8c89dfd9 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 2 Sep 2019 22:01:02 -0600 Subject: reverse_proxy: WIP refactor and support for FastCGI --- modules/caddyhttp/matchers.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'modules/caddyhttp/matchers.go') diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go index 0dac151..2ddefd0 100644 --- a/modules/caddyhttp/matchers.go +++ b/modules/caddyhttp/matchers.go @@ -616,10 +616,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 } } -- cgit v1.2.3 From 14f9662f9cc0f93e88d5efbbaf10de79070bea93 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 6 Sep 2019 12:36:45 -0600 Subject: Various fixes/tweaks to HTTP placeholder variables and file matching - Rename http.var.* -> http.vars.* to be more consistent - Prefixing a path matcher with * now invokes simple suffix matching - Handlers and matchers that need a root path default to {http.vars.root} - Clean replacer output on the file matcher's file selection suffix --- modules/caddyhttp/matchers.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/caddyhttp/matchers.go') diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go index 2ddefd0..7fc8aea 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 } -- cgit v1.2.3 From f6126acf379963136a6caeb818296a7510abd532 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 6 Sep 2019 14:25:16 -0600 Subject: Header matchers: allow matching presence of header with empty list --- modules/caddyhttp/matchers.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'modules/caddyhttp/matchers.go') diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go index 7fc8aea..4d0eea5 100644 --- a/modules/caddyhttp/matchers.go +++ b/modules/caddyhttp/matchers.go @@ -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 { @@ -625,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 { -- cgit v1.2.3