Skip to content

Commit

Permalink
Prefer an implicit codec when using the gRPC default
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.
  • Loading branch information
lrewega committed Dec 15, 2023
1 parent a990aad commit d993997
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions protocol_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@ func grpcContentTypeFromCodecName(web bool, name string) string {
if web {
return grpcWebContentTypePrefix + name
}
if name == codecNameProto {
// for compatibility with some servers prefer an implicit default codec
return grpcContentTypeDefault
}
return grpcContentTypePrefix + name
}

Expand Down

0 comments on commit d993997

Please sign in to comment.