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

Function BenchmarkHeaderREMatcher

modules/caddyhttp/matchers_test.go:983–1006  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

981}
982
983func BenchmarkHeaderREMatcher(b *testing.B) {
984 i := 0
985 match := MatchHeaderRE{"Field": &MatchRegexp{Pattern: "^foo(.*)$", Name: "name"}}
986 input := http.Header{"Field": []string{"foobar"}}
987 var host string
988 err := match.Provision(caddy.Context{})
989 if err != nil {
990 b.Errorf("Test %d %v: Provisioning: %v", i, match, err)
991 }
992 err = match.Validate()
993 if err != nil {
994 b.Errorf("Test %d %v: Validating: %v", i, match, err)
995 }
996
997 // set up the fake request and its Replacer
998 req := &http.Request{Header: input, URL: new(url.URL), Host: host}
999 repl := caddy.NewReplacer()
1000 ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
1001 req = req.WithContext(ctx)
1002 addHTTPVarsToReplacer(repl, req, httptest.NewRecorder())
1003 for b.Loop() {
1004 match.MatchWithError(req)
1005 }
1006}
1007
1008func TestVarREMatcher(t *testing.T) {
1009 for i, tc := range []struct {

Callers

nothing calls this directly

Calls 5

ProvisionMethod · 0.95
ValidateMethod · 0.95
MatchWithErrorMethod · 0.95
addHTTPVarsToReplacerFunction · 0.85
WithValueMethod · 0.80

Tested by

no test coverage detected