Skip to content

Commit

Permalink
Prefer an implicit codec when using the gRPC default (#655)
Browse files Browse the repository at this point in the history
Some gRPC servers in the wild appear to only accept requests when the
Content-Type subtype codec name is empty, implying the default of
"proto". For example Google Cloud API endpoints appear to require
Content-Type to be exactly `application/grpc` and disallow the
equivalent explicit form `application/grpc+proto`, rejecting requests
using the latter form by responding with a 404 and `Content-Type:
text/html`.

It's unclear if this is a load balancer (mis)configuration issue, or a
lack of support for specifying a codec in the server implementation, but
the end result is the same.

Seeing as the subtype qualifier is optional for gRPC, let's try to
prefer the implicit form when it is equivalent to the selected codec.

Note that this change only impacts gRPC. Elsewhere we continue to prefer
being explicit. This change should not impact servers.

---------

Co-authored-by: Akshay Shah <akshay@akshayshah.org>
  • Loading branch information
lrewega and akshayjshah authored Feb 6, 2024
1 parent 297532d commit 29524c2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions protocol_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,13 @@ func grpcContentTypeFromCodecName(web bool, name string) string {
if web {
return grpcWebContentTypePrefix + name
}
if name == codecNameProto {
// For compatibility with Google Cloud Platform's frontends, prefer an
// implicit default codec. See
// https://github.com/connectrpc/connect-go/pull/655#issuecomment-1915754523
// for details.
return grpcContentTypeDefault
}
return grpcContentTypePrefix + name
}

Expand Down

0 comments on commit 29524c2

Please sign in to comment.