Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check flusher before flush #817

Merged
merged 2 commits into from
Dec 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions go/grpcweb/grpc_web_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (w *grpcWebResponse) Flush() {
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.
w.wrapped.(http.Flusher).Flush()
flushWriter(w.wrapped)
}
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func (w *grpcWebResponse) finishRequest(req *http.Request) {
w.copyTrailersToPayload()
} else {
w.WriteHeader(http.StatusOK)
w.wrapped.(http.Flusher).Flush()
flushWriter(w.wrapped)
}
}

Expand All @@ -102,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.wrapped.(http.Flusher).Flush()
flushWriter(w.wrapped)
}

func extractTrailingHeaders(src http.Header, flushed http.Header) http.Header {
Expand Down Expand Up @@ -157,5 +157,14 @@ func (w *base64ResponseWriter) Flush() {
grpclog.Errorf("ignoring error Flushing base64 encoder: %v", err)
}
w.newEncoder()
w.wrapped.(http.Flusher).Flush()
flushWriter(w.wrapped)
}

func flushWriter(w http.ResponseWriter) {
f, ok := w.(http.Flusher)
if !ok {
return
}

f.Flush()
}