Metadata from server to client

1,784 views
Skip to first unread message

chil...@gmail.com

unread,
Dec 4, 2017, 9:32:15 AM12/4/17
to grpc.io
Hi all,

i'm trying to use the context metadata aside from the pure RPC communication between my client and server.

In this code example (https://gitlab.com/pantomath-io/demo-grpc/blob/add-auth), I have a client adding a login/password in the metadata sent to the server. This latest uses an UnaryInterceptor to extract the metadata from the context, and to process the RPC call (or block it).

Now, I'd like the server to inject metadata in the *response* to the client, and the client to read it (for instance, the server could inject a serial number in the response).

I'm quite confused on how to do that:
- do the client and server share the same context? (ie the server should set the metadata in the context it knows, and the client would read it from there?)
- are SetHeader() [1] and SetTrailer() [2] functions made just for that? If so, is it only in the case of stream (as opposed to RPC calls)?
- is there any mechanism to make this exchange systematic (like the Interceptor)?

Many thanks,
julien


chil...@gmail.com

unread,
Dec 4, 2017, 1:05:05 PM12/4/17
to grpc.io
I finally found my way: https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md

So basically, grpc.SetHeader() + grpc.SendHeader() and grpc.SetTrailer() are totally what I was looking for. On the client side, grpc.Header() and grpc.Trailer() functions need to be passed to the RPC call, and their argument is a metadata.MD object to be filled.
Reply all
Reply to author
Forward
0 new messages