summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers_test.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2021-02-11 16:27:09 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2021-02-11 16:27:09 -0700
commitcc63c5805e1587d7e5901deaad3f5bac944a2cf6 (patch)
tree174d047375d6c57e4e18f9a92570a6d1ad582b4e /modules/caddyhttp/matchers_test.go
parent51e3fdba7738e577b5ccfbad5bd7712fa594afc0 (diff)
caddyhttp: Support placeholders in header matcher values (close #3916)
Diffstat (limited to 'modules/caddyhttp/matchers_test.go')
-rw-r--r--modules/caddyhttp/matchers_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index ab4487d..5163df1 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -397,6 +397,9 @@ func TestPathREMatcher(t *testing.T) {
}
func TestHeaderMatcher(t *testing.T) {
+ repl := caddy.NewReplacer()
+ repl.Set("a", "foobar")
+
for i, tc := range []struct {
match MatchHeader
input http.Header // make sure these are canonical cased (std lib will do that in a real request)
@@ -490,8 +493,26 @@ func TestHeaderMatcher(t *testing.T) {
input: http.Header{"Must-Not-Exist": []string{"do not match"}},
expect: false,
},
+ {
+ match: MatchHeader{"Foo": []string{"{a}"}},
+ input: http.Header{"Foo": []string{"foobar"}},
+ expect: true,
+ },
+ {
+ match: MatchHeader{"Foo": []string{"{a}"}},
+ input: http.Header{"Foo": []string{"asdf"}},
+ expect: false,
+ },
+ {
+ match: MatchHeader{"Foo": []string{"{a}*"}},
+ input: http.Header{"Foo": []string{"foobar-baz"}},
+ expect: true,
+ },
} {
req := &http.Request{Header: tc.input, Host: tc.host}
+ ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
+ req = req.WithContext(ctx)
+
actual := tc.match.Match(req)
if actual != tc.expect {
t.Errorf("Test %d %v: Expected %t, got %t for '%s'", i, tc.match, tc.expect, actual, tc.input)