Skip to content
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

Should allow colon in metadata keys for HTTP/2 pseudo headers? #104

Closed
mng12689 opened this issue Nov 28, 2017 · 3 comments
Closed

Should allow colon in metadata keys for HTTP/2 pseudo headers? #104

mng12689 opened this issue Nov 28, 2017 · 3 comments

Comments

@mng12689
Copy link

Hello,

I am trying to set a metadata key/value pair for an http/2 header like so:

var meta = new grpc.Metadata();
meta.add(':authority', 'account');

This fails with the following error:

Error: Metadata key":authority" contains illegal characters
web_1              |     at normalizeKey (/app/node_modules/grpc/src/node/src/metadata.js:67:11)
web_1              |     at Metadata.add (/app/node_modules/grpc/src/node/src/metadata.js:108:9)
web_1              |     at Promise (/app/src/functions/index.js:54:10)
web_1              |     at Object.createUserSession (/app/src/functions/index.js:52:10)
web_1              |     at createUserSession (/app/src/routes/index.js:8:23)
web_1              |     at Promise.resolve.then (/app/src/lib/promisify-grpc.js:6:16)
web_1              |     at process._tickDomainCallback (internal/process/next_tick.js:135:7)
web_1              | Processing [/auth.Authenticator/CreateUserSession]

The problem is that Metadata.add() does not allow a key value pair with a key that contains a colon. However, shouldn't this be allowed considering the HTTP/2 spec specifies that pseudo headers (such as :authority) are supposed to be implemented with a leading colon?

Link to offending code:
https://github.com/grpc/grpc-node/blob/master/packages/grpc-js-core/src/metadata.ts

P.S. I did find this issue, which identifies the same problem, but does not actually discuss whether or not metadata keys SHOULD support a colon: grpc/grpc-go#613

P.P.S. Just to provide some context, I want to use the :authority header because Envoy proxy relies on this header to determine where a request should be forwarded to. Though this has little to do with gRPC, thought it might be useful to provide a legitimate use case. https://www.envoyproxy.io/docs/envoy/latest/intro/deployment_types/service_to_service.html#service-to-service-egress-listener

@mng12689
Copy link
Author

I also just realized that gRPC metadata is not the same thing as HTTP/2 headers (and I'm guessing aren't implemented as such), in which case this issue is probably not relevant. Is there a way to modify the underlying HTTP/2 headers for a gRPC request?

@murgatroid99
Copy link
Member

You can't directly set the :authority header because gRPC internally handles HTTP2 protocol pseudo-headers. You can modify the authority for an entire client by setting the option "grpc.default_authority" at client construction, and I think you can set it for a single call by passing it in the host key in the options call argument.

gRPC metadata does in fact correspond directly to HTTP2 headers.

@imseon
Copy link

imseon commented Mar 7, 2018

@murgatroid99 It works fine! Thanks

@lock lock bot locked as resolved and limited conversation to collaborators Sep 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants