From bd14c94c7ca22168409a63b1d816282cb7e4755b Mon Sep 17 00:00:00 2001 From: Luke Rewega Date: Fri, 15 Dec 2023 16:52:04 -0500 Subject: [PATCH 1/2] Prefer an implicit codec when using the gRPC default 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. --- protocol_grpc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/protocol_grpc.go b/protocol_grpc.go index b14f2293..c93cddd0 100644 --- a/protocol_grpc.go +++ b/protocol_grpc.go @@ -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 } From 95e6796f01e35592bcc9f17f4388ba8599d97b85 Mon Sep 17 00:00:00 2001 From: Akshay Shah Date: Tue, 6 Feb 2024 11:29:03 -0800 Subject: [PATCH 2/2] Make comment more explicit re: GCP bugs --- protocol_grpc.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/protocol_grpc.go b/protocol_grpc.go index c93cddd0..1e3b5d54 100644 --- a/protocol_grpc.go +++ b/protocol_grpc.go @@ -847,7 +847,10 @@ func grpcContentTypeFromCodecName(web bool, name string) string { return grpcWebContentTypePrefix + name } if name == codecNameProto { - // for compatibility with some servers prefer an implicit default codec + // 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