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

What is the best practice for response meta-data when using interceptors?

Open DWIAltonaAnalytics opened this issue 2 years ago • 1 comments

I have a problem handling response meta data on the server side.

I would like to include some information in any response my server sends, so an interceptor came to mind. But WriteResponseHeadersAsync can only be called once and thus using it within an interceptor forbids itself as it would be hard to document and makes using the method elsewhere impossible. I can change the trailers of any response perfectly fine in interceptors and chain as many as I want, but if I want to write information to the header, there is no way.

why isn't the repsonse header handled the same as the trailer, or the client-sides headers? Have a Metadata-object within the context, anyone can change it and the underlying framework sends them when the actual response is send?

DWIAltonaAnalytics avatar Jan 02 '24 12:01 DWIAltonaAnalytics

I don't know. I didn't design the API. I agree it's a limitation.

What you could do is access the underlying HttpContext in the interceptor and add headers to HttpContext.Response.Headers.

JamesNK avatar Jan 02 '24 12:01 JamesNK