From e5bbed10461f8baa3c75e4614edb8d44d3252bb5 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 26 May 2020 17:35:27 -0600 Subject: caddyhttp: Refactor header matching This allows response matchers to benefit from the same matching logic as the request header matchers (mainly prefix/suffix wildcards). --- modules/caddyhttp/matchers_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'modules/caddyhttp/matchers_test.go') diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go index 021bb98..9b3a9a8 100644 --- a/modules/caddyhttp/matchers_test.go +++ b/modules/caddyhttp/matchers_test.go @@ -448,6 +448,21 @@ func TestHeaderMatcher(t *testing.T) { input: http.Header{"Field2": []string{"foo"}}, 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{}, @@ -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 { -- cgit v1.2.3