@marcel91200 / caddy Mirror · read-only / commits / 96058538
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: Logging for streaming and upgrades (#3689)

* reverseproxy: Enable error logging for connection upgrades * reverseproxy: Change some of the error levels, unsugar * Use unsugared log in one spot Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>

Francis Lavoie committed Nov 20, 2020 at 16:24 UTC 96058538f01bf3fc4f2f7c25dbb2338f058f46c7
1 file changed +8 -7
modules/caddyhttp/reverseproxy/streaming.go
+8 -7
@@ -33,8 +33,9 @@ func (h Handler) handleUpgradeResponse(rw http.ResponseWriter, req *http.Request
33 reqUpType := upgradeType(req.Header)
34 resUpType := upgradeType(res.Header)
35 if reqUpType != resUpType {
36 - // TODO: figure out our own error handling
37 - // p.getErrorHandler()(rw, req, fmt.Errorf("backend tried to switch protocol %q when %q was requested", resUpType, reqUpType))
36 + h.logger.Debug("backend tried to switch to unexpected protocol via Upgrade header",
37 + zap.String("backend_upgrade", resUpType),
38 + zap.String("requested_upgrade", reqUpType))
39 return
40 }
41
@@ -42,12 +43,12 @@ func (h Handler) handleUpgradeResponse(rw http.ResponseWriter, req *http.Request
43
44 hj, ok := rw.(http.Hijacker)
45 if !ok {
45 - // p.getErrorHandler()(rw, req, fmt.Errorf("can't switch protocols using non-Hijacker ResponseWriter type %T", rw))
46 + h.logger.Sugar().Errorf("can't switch protocols using non-Hijacker ResponseWriter type %T", rw)
47 return
48 }
49 backConn, ok := res.Body.(io.ReadWriteCloser)
50 if !ok {
50 - // p.getErrorHandler()(rw, req, fmt.Errorf("internal error: 101 switching protocols response with non-writable body"))
51 + h.logger.Error("internal error: 101 switching protocols response with non-writable body")
52 return
53 }
54
@@ -66,17 +67,17 @@ func (h Handler) handleUpgradeResponse(rw http.ResponseWriter, req *http.Request
67
68 conn, brw, err := hj.Hijack()
69 if err != nil {
69 - // p.getErrorHandler()(rw, req, fmt.Errorf("Hijack failed on protocol switch: %v", err))
70 + h.logger.Error("Hijack failed on protocol switch", zap.Error(err))
71 return
72 }
73 defer conn.Close()
74 res.Body = nil // so res.Write only writes the headers; we have res.Body in backConn above
75 if err := res.Write(brw); err != nil {
75 - // p.getErrorHandler()(rw, req, fmt.Errorf("response write: %v", err))
76 + h.logger.Debug("response write", zap.Error(err))
77 return
78 }
79 if err := brw.Flush(); err != nil {
79 - // p.getErrorHandler()(rw, req, fmt.Errorf("response flush: %v", err))
80 + h.logger.Debug("response flush", zap.Error(err))
81 return
82 }
83 errc := make(chan error, 1)