grpc-swift icon indicating copy to clipboard operation
grpc-swift copied to clipboard

Specify Metadata That is Sent From Server to Client

Open qusc opened this issue 4 years ago • 2 comments

Under https://grpc.io/docs/what-is-grpc/core-concepts/#metadata it is stated that metadata

[...] lets the client provide information associated with the call to the server and vice versa.

From that I understand that (initial) metadata can also be sent back to the client when e.g. starting a server-side streaming call. However, I can't find a way in the GRPCSwift API to specify the metadata that should be sent by the server back to the client when a call is initiated.

What are you trying to achieve?

I am trying to attach metadata to a streaming call server-side so that the client can check it before receiving any actual messages from the stream. Like

let callOptions = CallOptions(customMetadata: .init([("my-header", "my-data")]))
let streamingCall = grpcClient.myStreamingCall(myRequest, callOptions: callOptions) { ... }

but server-side.

What have you tried so far?

I have tried to find any hint to attach / send metadata server-side in the public API.

qusc avatar Feb 09 '21 21:02 qusc

Unfortunately it's not quite as easy on the server as it is on the client. The only way to do this with the current API would be with a server interceptor (https://github.com/grpc/grpc-swift/blob/main/docs/interceptors-tutorial.md); you can intercept the .metadata case in send to attach any additional metadata.

glbrntt avatar Feb 10 '21 08:02 glbrntt

FWIW: there is support for sending headers from within the server call handler in the async/await gRPC flavour (which is currently experimental).

glbrntt avatar Oct 07 '21 13:10 glbrntt