git » gofer » commit c6aff14

http proxy: Support the Flusher interface

author Alberto Bertogli
2021-04-07 19:56:23 UTC
committer Alberto Bertogli
2021-04-07 19:56:23 UTC
parent 5f71e1037346d453827ac9373663595f8d749636

http proxy: Support the Flusher interface

When proxying, we might want to proxy intermediate results. To do this,
the reverse proxy needs the writer to support the http.Flusher
interface.

server/http.go +9 -0

diff --git a/server/http.go b/server/http.go
index f42db99..11211ce 100644
--- a/server/http.go
+++ b/server/http.go
@@ -400,6 +400,15 @@ func (w *statusWriter) ReadFrom(src io.Reader) (int64, error) {
 	return n, err
 }
 
+// Flush is optional but makes it support the http.Flusher interface, which is
+// needed for things like server-side events.
+func (w *statusWriter) Flush() {
+	flusher, ok := w.ResponseWriter.(http.Flusher)
+	if ok {
+		flusher.Flush()
+	}
+}
+
 func SetHeader(parent http.Handler, hdrs map[string]string) http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		tr, _ := trace.FromContext(r.Context())