@marcel91200 / caddy Mirror · read-only / commits / 9ee01dce
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

reverseproxy: Make debug log safe if error occurs

Matthew Holt committed May 18, 2020 at 14:08 UTC 9ee01dceac0a3e9f71c3b37dfbe3ae04e2f54986
1 file changed +8 -4
modules/caddyhttp/reverseproxy/reverseproxy.go
+8 -4
@@ -461,20 +461,24 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, di Dia
461 // point the request to this upstream
462 h.directRequest(req, di)
463
464 - // do the round-trip
464 + // do the round-trip; emit debug log with values we know are
465 + // safe, or if there is no error, emit fuller log entry
466 start := time.Now()
467 res, err := h.Transport.RoundTrip(req)
468 duration := time.Since(start)
468 - h.logger.Debug("upstream roundtrip",
469 + logger := h.logger.With(
470 zap.String("upstream", di.Upstream.String()),
471 zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: req}),
471 - zap.Object("headers", caddyhttp.LoggableHTTPHeader(res.Header)),
472 zap.Duration("duration", duration),
473 - zap.Int("status", res.StatusCode),
473 )
474 if err != nil {
475 + logger.Debug("upstream roundtrip", zap.Error(err))
476 return err
477 }
478 + logger.Debug("upstream roundtrip",
479 + zap.Object("headers", caddyhttp.LoggableHTTPHeader(res.Header)),
480 + zap.Int("status", res.StatusCode),
481 + )
482
483 // update circuit breaker on current conditions
484 if di.Upstream.cb != nil {