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

Only use trailers-only response in grpc-web when there are no custom headers #677

Merged
merged 1 commit into from
Feb 7, 2024
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
12 changes: 4 additions & 8 deletions protocol_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,10 @@ func (hc *grpcHandlerConn) Close(err error) (retErr error) {
)
mergeHeaders(mergedTrailers, hc.responseTrailer)
grpcErrorToTrailer(mergedTrailers, hc.protobuf, err)
if hc.web && !hc.wroteToBody {
// We're using gRPC-Web and we haven't yet written to the body. Since we're
// not sending any response messages, the gRPC specification calls this a
// "trailers-only" response. Under those circumstances, the gRPC-Web spec
// says that implementations _may_ send trailing metadata as HTTP headers
// instead. Envoy is the canonical implementation of the gRPC-Web protocol,
// so we emulate Envoy's behavior and put the trailing metadata in the HTTP
// headers.
if hc.web && !hc.wroteToBody && len(hc.responseHeader) == 0 {
// We're using gRPC-Web, we haven't yet written to the body, and there are no
// custom headers. That means we can send a "trailers-only" response and send
// trailing metadata as HTTP headers (instead of as trailers).
mergeHeaders(hc.responseWriter.Header(), mergedTrailers)
return nil
}
Expand Down
Loading