mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-26 00:02:45 -04:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									6e0849d4c2
								
							
						
					
					
						commit
						96058538f0
					
				| @ -33,8 +33,9 @@ func (h Handler) handleUpgradeResponse(rw http.ResponseWriter, req *http.Request | |||||||
| 	reqUpType := upgradeType(req.Header) | 	reqUpType := upgradeType(req.Header) | ||||||
| 	resUpType := upgradeType(res.Header) | 	resUpType := upgradeType(res.Header) | ||||||
| 	if reqUpType != resUpType { | 	if reqUpType != resUpType { | ||||||
| 		// TODO: figure out our own error handling | 		h.logger.Debug("backend tried to switch to unexpected protocol via Upgrade header", | ||||||
| 		// p.getErrorHandler()(rw, req, fmt.Errorf("backend tried to switch protocol %q when %q was requested", resUpType, reqUpType)) | 			zap.String("backend_upgrade", resUpType), | ||||||
|  | 			zap.String("requested_upgrade", reqUpType)) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -42,12 +43,12 @@ func (h Handler) handleUpgradeResponse(rw http.ResponseWriter, req *http.Request | |||||||
| 
 | 
 | ||||||
| 	hj, ok := rw.(http.Hijacker) | 	hj, ok := rw.(http.Hijacker) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		// p.getErrorHandler()(rw, req, fmt.Errorf("can't switch protocols using non-Hijacker ResponseWriter type %T", rw)) | 		h.logger.Sugar().Errorf("can't switch protocols using non-Hijacker ResponseWriter type %T", rw) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	backConn, ok := res.Body.(io.ReadWriteCloser) | 	backConn, ok := res.Body.(io.ReadWriteCloser) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		// p.getErrorHandler()(rw, req, fmt.Errorf("internal error: 101 switching protocols response with non-writable body")) | 		h.logger.Error("internal error: 101 switching protocols response with non-writable body") | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -66,17 +67,17 @@ func (h Handler) handleUpgradeResponse(rw http.ResponseWriter, req *http.Request | |||||||
| 
 | 
 | ||||||
| 	conn, brw, err := hj.Hijack() | 	conn, brw, err := hj.Hijack() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		// p.getErrorHandler()(rw, req, fmt.Errorf("Hijack failed on protocol switch: %v", err)) | 		h.logger.Error("Hijack failed on protocol switch", zap.Error(err)) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	defer conn.Close() | 	defer conn.Close() | ||||||
| 	res.Body = nil // so res.Write only writes the headers; we have res.Body in backConn above | 	res.Body = nil // so res.Write only writes the headers; we have res.Body in backConn above | ||||||
| 	if err := res.Write(brw); err != nil { | 	if err := res.Write(brw); err != nil { | ||||||
| 		// p.getErrorHandler()(rw, req, fmt.Errorf("response write: %v", err)) | 		h.logger.Debug("response write", zap.Error(err)) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	if err := brw.Flush(); err != nil { | 	if err := brw.Flush(); err != nil { | ||||||
| 		// p.getErrorHandler()(rw, req, fmt.Errorf("response flush: %v", err)) | 		h.logger.Debug("response flush", zap.Error(err)) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	errc := make(chan error, 1) | 	errc := make(chan error, 1) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user