mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 10:12:29 +08:00 
			
		
		
		
	reverseproxy: Remove redundant flushing (#4299)
From reading through the code, I think this code path is now obsoleted by the changes made in https://github.com/caddyserver/caddy/pull/4266. Basically, `h.flushInterval()` will set the flush interval to `-1` if we're in a bi-directional stream, and the recent PR ensured that `h.copyResponse()` properly flushes headers immediately when the flush interval is non-zero. So now there should be no need to call Flush before calling `h.copyResponse()`.
This commit is contained in:
		@ -691,15 +691,6 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, repl *
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rw.WriteHeader(res.StatusCode)
 | 
						rw.WriteHeader(res.StatusCode)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// some apps need the response headers before starting to stream content with http2,
 | 
					 | 
				
			||||||
	// so it's important to explicitly flush the headers to the client before streaming the data.
 | 
					 | 
				
			||||||
	// (see https://github.com/caddyserver/caddy/issues/3556 for use case and nuances)
 | 
					 | 
				
			||||||
	if h.isBidirectionalStream(req, res) {
 | 
					 | 
				
			||||||
		if wf, ok := rw.(http.Flusher); ok {
 | 
					 | 
				
			||||||
			wf.Flush()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	err = h.copyResponse(rw, res.Body, h.flushInterval(req, res))
 | 
						err = h.copyResponse(rw, res.Body, h.flushInterval(req, res))
 | 
				
			||||||
	res.Body.Close() // close now, instead of defer, to populate res.Trailer
 | 
						res.Body.Close() // close now, instead of defer, to populate res.Trailer
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user