-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Allow override for Content-Type
header in order to support encoder selection based on Content Sub-Type
#10959
Comments
Confirming the need for it, see #11023 |
You are requesting full control over
If the Go server supports both, why are you wanting to use JSON? (In other words, why can't you use protobuf?) The sub-type format is very broken. It is being used for the opposite of what the standard says it means and its name is very confusing. "subtype" in Content-Type is the part after the "/", so for "application/grpc" "grpc" would be the subtype and for "text/plain" "plain" would be the subtype. Clearly "subtype" in the gRPC wire spec is not that. The Yes, grpc-go is using it. And yes, it is in the grpc protocol spec. But it is a bad idea to propagate it further than Go. I think the easiest solution here is a separate header that holds the message content type. Something like "grpc-message-content-type". (This could potentially also replace "grpc-message-type", which to my knowledge is unused in practice, as content-type could specify the message schema. For protobuf maybe (Another option would be to use parameters in grpc itself, like I have spoken to grpc-go folks about this, and it may be possible to migrate to a better approach while keeping the current API. But clearly there is some work involved. |
This will be tracked in the grpc/grpc repo instead. One of grpc/grpc#36765 and grpc/grpc#36766 will track parts of this. We want to discourage the subtype approach and someone could work on figuring out what the replacement should be. |
Is your feature request related to a problem?
grpc-java
withNetty
transport currently considersContent-Type
header as a reserved header and disregards the value ofContent-Type
provided by user (Can find a similar issue withUser-Agent
here at #5874).This is problematic in cases where content sub-type based encoder selection is required at server side. (Check #7321)
Describe the solution you'd like
grpc-netty
must not considerContent-Type
header as a reserved header since a core gRPC functionality is not working because override ofContent-Type
from currently forcedapplication/grpc
toapplication/grpc+<content sub-type>
is not possible.This would require removal of:
grpc-java/netty/src/main/java/io/grpc/netty/Utils.java
Line 232 in 0ffcd40
grpc-java/netty/src/main/java/io/grpc/netty/Utils.java
Line 247 in 0ffcd40
Further, additional validations can be added to check if value of
Content-Type
is valid according to gRPC protocol specification. (Basically checking if value ofContent-Type
starts withapplication/grpc
).Describe alternatives you've considered
An alternative would be to deprecate registering global encoders in gRPC implementations for various languages (like Go) in favour of registering
Marshaller
s likegrpc-java
'sMethodDescriptor.Marshaller<T>
which is not currently supported in gRPC implementations for these languages. This would be rather tedious to incorporate.Additional context
This issue with not being able to set a custom override for
Content-Type
header is posing a problem for us as we need to communicate with a Go gRPC application using JSON content sub-type. The way encoding works on go-grpc side is that it chooses one of the registered encoders based on content subtype fromContent-Type
header, soapplication/grpc+json
will use the registered encoder with namejson
. However sinceNetty
transport library is overriding it withapplication/grpc
(considering it a reserved header),go-grpc
is falling back on using the default encoder with content sub-type name ofproto
.Further, the Go server needs to support both
protobuf
andjson
based encoding.The text was updated successfully, but these errors were encountered: