NewTestReplacer creates a replacer for an http.Request for use in tests that are not in this package
(req *http.Request)
| 48 | // NewTestReplacer creates a replacer for an http.Request |
| 49 | // for use in tests that are not in this package |
| 50 | func 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 | |
| 58 | func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.ResponseWriter) { |
| 59 | SetVar(req.Context(), "start_time", time.Now()) |