How to set custom headers on a request

4,805 views
Skip to first unread message

jdov...@gmail.com

unread,
Aug 1, 2016, 6:59:14 PM8/1/16
to grpc.io
If I wanted to add a custom header to a gRPC request, can I do that?

For example, say I wanted to know which user is making the request, I'd like to add a header called "user" when making the client request. I might also want to add a header called "password" in case I wanted to authenticate them.

Can I add arbitrary headers like in HTTP/1 and can that be accomplished in the various gRPC apis (Java, C#, Node, etc).

TIA





Eric Anderson

unread,
Aug 1, 2016, 7:11:14 PM8/1/16
to jdov...@gmail.com, grpc.io
On Mon, Aug 1, 2016 at 3:59 PM, <jdov...@gmail.com> wrote:
If I wanted to add a custom header to a gRPC request, can I do that?

Can I add arbitrary headers like in HTTP/1 and can that be accomplished in the various gRPC apis (Java, C#, Node, etc).

The gRPC term for that is "Metadata". It's effectively HTTP headers. In Java, you need to use a ClientInterceptor to add the metadata, and a ServerInterceptor to retrieve it. You then could then use Context (and Contexts.interceptCall) to make the value available to your application. The ServerInterceptor is intended to be a central point of verification and policy.

It probably shouldn't be too hard to figure out how to use Metadata in the other languages, now that you know what you're looking for.
Reply all
Reply to author
Forward
0 new messages