mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-31 08:15:55 +08:00
perf: use zap's Check() to prevent useless allocs (#6560)
* perf: use zap's Check() to prevent useless allocs * fix * fix * fix * fix * restore previous replacer behavior * fix linter
This commit is contained in:
@ -133,19 +133,17 @@ func (rewr Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
|
||||
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
|
||||
const message = "rewrote request"
|
||||
|
||||
if rewr.logger.Check(zap.DebugLevel, message) == nil {
|
||||
c := rewr.logger.Check(zap.DebugLevel, message)
|
||||
if c == nil {
|
||||
rewr.Rewrite(r, repl)
|
||||
return next.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
logger := rewr.logger.With(
|
||||
zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: r}),
|
||||
)
|
||||
|
||||
changed := rewr.Rewrite(r, repl)
|
||||
|
||||
if changed {
|
||||
logger.Debug(message,
|
||||
c.Write(
|
||||
zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: r}),
|
||||
zap.String("method", r.Method),
|
||||
zap.String("uri", r.RequestURI),
|
||||
)
|
||||
|
Reference in New Issue
Block a user