Skip to content

Commit a3e02df

Browse files
committed
uses zap's .WithLazy with the original request
1 parent ff67b97 commit a3e02df

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

modules/caddyhttp/server.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,20 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
312312
}
313313
}
314314

315+
// restore original request before invoking error handler chain (issue #3717)
316+
// TODO: this does not restore original headers, if modified (for efficiency)
317+
origReq := r.Context().Value(OriginalRequestCtxKey).(http.Request)
318+
315319
// encode the request for logging purposes before
316320
// it enters any handler chain; this is necessary
317321
// to capture the original request in case it gets
318322
// modified during handling
319323
shouldLogCredentials := s.Logs != nil && s.Logs.ShouldLogCredentials
320324
loggableReq := zap.Object("request", LoggableHTTPRequest{
321-
Request: r,
325+
Request: &origReq,
322326
ShouldLogCredentials: shouldLogCredentials,
323327
})
324-
errLog := s.errorLogger.With(loggableReq)
328+
errLog := s.errorLogger.WithLazy(loggableReq)
325329

326330
var duration time.Duration
327331

@@ -366,9 +370,6 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
366370
return
367371
}
368372

369-
// restore original request before invoking error handler chain (issue #3717)
370-
// TODO: this does not restore original headers, if modified (for efficiency)
371-
origReq := r.Context().Value(OriginalRequestCtxKey).(http.Request)
372373
r.Method = origReq.Method
373374
r.RemoteAddr = origReq.RemoteAddr
374375
r.RequestURI = origReq.RequestURI

0 commit comments

Comments
 (0)