diff options
author | Alexander Stecher <[email protected]> | 2024-08-30 16:46:51 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-08-30 08:46:51 -0600 |
commit | ffd28be90ab85206474739b1f479ef49a6f0d7c3 (patch) | |
tree | 64790bcb6b948d4e88f091e0daba7b1937cb4c6b /modules | |
parent | 141c785420aa1cc8fd35e5fd2defa7b8af230a2f (diff) | |
download | caddy-ffd28be90ab85206474739b1f479ef49a6f0d7c3.tar.gz caddy-ffd28be90ab85206474739b1f479ef49a6f0d7c3.zip |
rewrite: Only serialize request if necessary (#6541)
* Prevents serializing the caddy request if log level is not debug.
* Extracts message to const.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/rewrite/rewrite.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/caddyhttp/rewrite/rewrite.go b/modules/caddyhttp/rewrite/rewrite.go index 9a4995186..c45ad98a2 100644 --- a/modules/caddyhttp/rewrite/rewrite.go +++ b/modules/caddyhttp/rewrite/rewrite.go @@ -131,6 +131,12 @@ func (rewr *Rewrite) Provision(ctx caddy.Context) error { func (rewr Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error { repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer) + const message = "rewrote request" + + if rewr.logger.Check(zap.DebugLevel, message) == nil { + rewr.Rewrite(r, repl) + return next.ServeHTTP(w, r) + } logger := rewr.logger.With( zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: r}), @@ -139,7 +145,7 @@ func (rewr Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy changed := rewr.Rewrite(r, repl) if changed { - logger.Debug("rewrote request", + logger.Debug(message, zap.String("method", r.Method), zap.String("uri", r.RequestURI), ) |