From 4e388ad97fdab93b4dc44664e991d90a7ef1b3d9 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst Date: Tue, 6 Aug 2019 12:14:04 +0100 Subject: [PATCH] Revert "Check flusher interface before calling Flush (#479)" (#527) This reverts commit cf7d15a039114df2a0e3a18002705bb67fdd5167. This introduced a recursive call to `Flush` in the proxy, which will crash the application. --- go/grpcweb/grpc_web_response.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/go/grpcweb/grpc_web_response.go b/go/grpcweb/grpc_web_response.go index 72d17c8d..c66eaf6c 100644 --- a/go/grpcweb/grpc_web_response.go +++ b/go/grpcweb/grpc_web_response.go @@ -59,15 +59,10 @@ func (w *grpcWebResponse) WriteHeader(code int) { } func (w *grpcWebResponse) Flush() { - f, ok := w.wrapped.(http.Flusher) - if !ok { - return - } - if w.wroteHeaders || w.wroteBody { // Work around the fact that WriteHeader and a call to Flush would have caused a 200 response. // This is the case when there is no payload. - f.Flush() + w.wrapped.(http.Flusher).Flush() } } @@ -95,7 +90,7 @@ func (w *grpcWebResponse) finishRequest(req *http.Request) { w.copyTrailersToPayload() } else { w.WriteHeader(http.StatusOK) - w.Flush() + w.wrapped.(http.Flusher).Flush() } } @@ -107,7 +102,7 @@ func (w *grpcWebResponse) copyTrailersToPayload() { binary.BigEndian.PutUint32(trailerGrpcDataHeader[1:5], uint32(trailerBuffer.Len())) w.wrapped.Write(trailerGrpcDataHeader) w.wrapped.Write(trailerBuffer.Bytes()) - w.Flush() + w.wrapped.(http.Flusher).Flush() } func extractTrailingHeaders(src http.Header, flushed http.Header) http.Header { @@ -162,5 +157,5 @@ func (w *base64ResponseWriter) Flush() { grpclog.Errorf("ignoring error Flushing base64 encoder: %v", err) } w.newEncoder() - w.Flush() + w.wrapped.(http.Flusher).Flush() }