Skip to content

Commit

Permalink
Ensure response writer newline delimits on flush
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Nov 25, 2024
1 parent 6686432 commit 25443cf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions protocol_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ func (w *grpcWebTextResponseWriter) Flush() {
_ = w.encoder.Close()
w.encoder = nil
}
// Some clients may expect a newline after each message. This does not
// affect the base64 encoding.
_, _ = w.ResponseWriter.Write([]byte{'\n'})
if flusher, ok := w.ResponseWriter.(http.Flusher); ok {
flusher.Flush()
}
Expand Down
2 changes: 1 addition & 1 deletion protocol_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestGRPCWebTextResponseWriter(t *testing.T) {
require.NoError(t, err)
writer.Flush()

assert.Equal(t, "SGVsbG8sIOS4lueVjA==SGVsbG8sIOS4lueVjA==", rec.Body.String())
assert.Equal(t, "SGVsbG8sIOS4lueVjA==\nSGVsbG8sIOS4lueVjA==\n", rec.Body.String())
assert.Equal(t, "application/grpc-web-text+proto", rec.Header().Get("Content-Type"))

out, err := io.ReadAll(newGRPCWebTextReader(strings.NewReader(rec.Body.String())))
Expand Down

0 comments on commit 25443cf

Please sign in to comment.