aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/matchers_test.go
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2020-05-26 17:35:27 -0600
committerMatthew Holt <[email protected]>2020-05-26 17:35:27 -0600
commite5bbed10461f8baa3c75e4614edb8d44d3252bb5 (patch)
treee0df2de9f1e2696c440d3783b7d14e62193018a3 /modules/caddyhttp/matchers_test.go
parent294910c68c315af41f4f47ec6c767fbe318c0e43 (diff)
downloadcaddy-e5bbed10461f8baa3c75e4614edb8d44d3252bb5.tar.gz
caddy-e5bbed10461f8baa3c75e4614edb8d44d3252bb5.zip
caddyhttp: Refactor header matching
This allows response matchers to benefit from the same matching logic as the request header matchers (mainly prefix/suffix wildcards).
Diffstat (limited to 'modules/caddyhttp/matchers_test.go')
-rw-r--r--modules/caddyhttp/matchers_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index 021bb9838..9b3a9a857 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -449,6 +449,21 @@ func TestHeaderMatcher(t *testing.T) {
expect: false,
},
{
+ match: MatchHeader{"Field1": []string{"foo*"}},
+ input: http.Header{"Field1": []string{"foo"}},
+ expect: true,
+ },
+ {
+ match: MatchHeader{"Field1": []string{"foo*"}},
+ input: http.Header{"Field1": []string{"asdf", "foobar"}},
+ expect: true,
+ },
+ {
+ match: MatchHeader{"Field1": []string{"*bar"}},
+ input: http.Header{"Field1": []string{"asdf", "foobar"}},
+ expect: true,
+ },
+ {
match: MatchHeader{"host": []string{"localhost"}},
input: http.Header{},
host: "localhost",
@@ -814,6 +829,24 @@ func TestResponseMatcher(t *testing.T) {
hdr: http.Header{"Foo": []string{"bar"}, "Foo2": []string{"baz"}},
expect: true,
},
+ {
+ require: ResponseMatcher{
+ Headers: http.Header{
+ "Foo": []string{"foo*"},
+ },
+ },
+ hdr: http.Header{"Foo": []string{"foobar"}},
+ expect: true,
+ },
+ {
+ require: ResponseMatcher{
+ Headers: http.Header{
+ "Foo": []string{"foo*"},
+ },
+ },
+ hdr: http.Header{"Foo": []string{"foobar"}},
+ expect: true,
+ },
} {
actual := tc.require.Match(tc.status, tc.hdr)
if actual != tc.expect {