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

Function NewTestReplacer

modules/caddyhttp/replacer.go:50–56  ·  view source on GitHub ↗

NewTestReplacer creates a replacer for an http.Request for use in tests that are not in this package

(req *http.Request)

Source from the content-addressed store, hash-verified

48// NewTestReplacer creates a replacer for an http.Request
49// for use in tests that are not in this package
50func NewTestReplacer(req *http.Request) *caddy.Replacer {
51 repl := caddy.NewReplacer()
52 ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
53 *req = *req.WithContext(ctx)
54 addHTTPVarsToReplacer(repl, req, nil)
55 return repl
56}
57
58func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.ResponseWriter) {
59 SetVar(req.Context(), "start_time", time.Now())

Callers 10

TestHandlerFunction · 0.92
fileMatcherTestFunction · 0.92
TestPHPFileMatcherFunction · 0.92
TestMatchExpressionMatchFunction · 0.92
TestServer_LogRequestFunction · 0.85

Calls 2

addHTTPVarsToReplacerFunction · 0.85
WithValueMethod · 0.80

Tested by 10

TestHandlerFunction · 0.74
fileMatcherTestFunction · 0.74
TestPHPFileMatcherFunction · 0.74
TestMatchExpressionMatchFunction · 0.74
TestServer_LogRequestFunction · 0.68