MCPcopy
hub / github.com/caddyserver/caddy / TestHeaderMatcher

Function TestHeaderMatcher

modules/caddyhttp/matchers_test.go:642–768  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

640}
641
642func TestHeaderMatcher(t *testing.T) {
643 repl := caddy.NewReplacer()
644 repl.Set("a", "foobar")
645
646 for i, tc := range []struct {
647 match MatchHeader
648 input http.Header // make sure these are canonical cased (std lib will do that in a real request)
649 host string
650 expect bool
651 }{
652 {
653 match: MatchHeader{"Field": []string{"foo"}},
654 input: http.Header{"Field": []string{"foo"}},
655 expect: true,
656 },
657 {
658 match: MatchHeader{"Field": []string{"foo", "bar"}},
659 input: http.Header{"Field": []string{"bar"}},
660 expect: true,
661 },
662 {
663 match: MatchHeader{"Field": []string{"foo", "bar"}},
664 input: http.Header{"Alakazam": []string{"kapow"}},
665 expect: false,
666 },
667 {
668 match: MatchHeader{"Field": []string{"foo", "bar"}},
669 input: http.Header{"Field": []string{"kapow"}},
670 expect: false,
671 },
672 {
673 match: MatchHeader{"Field": []string{"foo", "bar"}},
674 input: http.Header{"Field": []string{"kapow", "foo"}},
675 expect: true,
676 },
677 {
678 match: MatchHeader{"Field1": []string{"foo"}, "Field2": []string{"bar"}},
679 input: http.Header{"Field1": []string{"foo"}, "Field2": []string{"bar"}},
680 expect: true,
681 },
682 {
683 match: MatchHeader{"field1": []string{"foo"}, "field2": []string{"bar"}},
684 input: http.Header{"Field1": []string{"foo"}, "Field2": []string{"bar"}},
685 expect: true,
686 },
687 {
688 match: MatchHeader{"field1": []string{"foo"}, "field2": []string{"bar"}},
689 input: http.Header{"Field1": []string{"foo"}, "Field2": []string{"kapow"}},
690 expect: false,
691 },
692 {
693 match: MatchHeader{"field1": []string{"*"}},
694 input: http.Header{"Field1": []string{"foo"}},
695 expect: true,
696 },
697 {
698 match: MatchHeader{"field1": []string{"*"}},
699 input: http.Header{"Field2": []string{"foo"}},

Callers

nothing calls this directly

Calls 3

SetMethod · 0.95
WithValueMethod · 0.80
MatchWithErrorMethod · 0.65

Tested by

no test coverage detected