Skip to content

Commit

Permalink
Only use trailers-only response in grpc-web when there are no custom …
Browse files Browse the repository at this point in the history
…headers (#677)
  • Loading branch information
jhump authored Feb 7, 2024
1 parent 29524c2 commit c83ce94
Showing 1 changed file with 4 additions and 8 deletions.
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

0 comments on commit c83ce94

Please sign in to comment.