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

Revert "Check flusher interface before calling Flush (#479)" #527

Merged
merged 1 commit into from
Aug 6, 2019
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
13 changes: 4 additions & 9 deletions go/grpcweb/grpc_web_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -95,7 +90,7 @@ func (w *grpcWebResponse) finishRequest(req *http.Request) {
w.copyTrailersToPayload()
} else {
w.WriteHeader(http.StatusOK)
w.Flush()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johanbrandhorst whilst we wait for CI to go green on this PR...

...isn't this the root cause of the issue? Shouldn't this be replaced with a safe up-cast on w.wrapped before calling Flush()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked at it in detail, lets discuss after merging the fix.

w.wrapped.(http.Flusher).Flush()
}
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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()
}