-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Pass Permanent Request Headers #213
Pass Permanent Request Headers #213
Conversation
return true | ||
} | ||
switch hdr { | ||
case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I was concerned that this would be slow because of a bunch of calls to strcmp. Turns out that golang builds a binary tree at compile time and uses that to search. Cool!
@yugui What do you think of this? |
Not sure why |
@achew22, @christianvozar But I wonder if we can have better handling of several HTTP headers in the whitelist.
How about the following approach?
|
I think that whitelist is very reasonable. Let's merge this. That closes bullet 1 and unblocks @christianvozar. I would like to think a little bit more about allowing users to add more to the whitelist. It feels like there is a good way to provide that flexibility and also to ensure the server remains as fast as can be. What do you think about proxying User-Agent as Grpc-Gateway-User-Agent? I don't think we should pass it through as the real User-Agent for the reasons you stated above but I think it would be reasonable to claim that in the header namespace. As for more permanent headers, I think we should wait for there to be a use case that necessitates the enhancement. Those are valid concerns. Maybe we could open an issue preemptively that says "please comment here if you are running into this?" |
Sounds good to me. What do you think, @christianvozar? |
The use case I am implementing is one where I am building an API using gRPC+JSON Gateway similar in design to one like Github's. One where a third-party developer utilizing the API might declare their So if we are all in agreement that @yugui 's whitelist is an appropriate one, that headers reserved for the gRPC wire protocol ( |
@christianvozar Right. It does not mean that API users need to specify BTW, now I remember that the prefix For versioning, the recommended way of implementation in gRPC is to define a different gRPC services or methods. And you can dispatch those versions in your custom http handler in your gateway. |
eae2f5f
to
815536c
Compare
Sorry for the delayed response in getting you this. Beware So for my use-case, as discussed previously, I am really only looking for most standard HTTP headers to be proxied to the gRPC server. That they have a prefix is totally fine, just so long as end-users/developers do not have to specify the prefix in their REST call. So to make life easier I prefix all standard HTTP Request Headers with I did not want to put the Sample cURL: Sample Metadata Context: |
// permenant request headers maintained by IANA. | ||
// http://www.iana.org/assignments/message-headers/message-headers.xml | ||
func isPermanentHTTPHeader(hdr string) bool { | ||
if hdr != "" && hdr[0] == ':' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What permanent headers start with ":"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None, solid point. I was under the impression (could be wrong here) that gRPC reserved headers start with :
and this was part of a check. Happy to remove it.
815536c
to
91c88f3
Compare
@christianvozar it appears that there are tests failing on Travis. Can you take a look at those? |
fc8c9c5
to
99d95a0
Compare
99d95a0
to
b2b57d2
Compare
any updates on getting this merged? |
@@ -52,16 +53,16 @@ func TestAnnotateContext_ForwardsGrpcMetadata(t *testing.T) { | |||
} | |||
md, ok := metadata.FromContext(annotated) | |||
if got, want := len(md), emptyForwardMetaCount+3; !ok || got != want { | |||
t.Errorf("Expected %d metadata items in context; got %d", got, want) | |||
t.Errorf("Expected %d metadata items in context; got %d", got, want, md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
md will never get printed. Nothing expects it in the string
Given the canonical MIME header key encoding we would likely want to make this 'Grpcgateway' as the header prefix. I don't love this but we should probably keep out of the way of 'Grpc-*'. |
as this is it will be a breaking change as 'authorization' is passed as 'grpcgateway-authorization' |
Closing as #252 addresses this |
Allows permanent request headers as-is and without
Grpc-Metadata-
prefix in metadata. This is particularly important if you are developing REST APIs where third-party developers will have expectations for headers such asAccept:
andUser-Agent:
.