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

Service implementations should be able to return metadata along a success response #872

Open
bjaglin opened this issue Mar 13, 2020 · 3 comments
Labels

Comments

@bjaglin
Copy link
Contributor

bjaglin commented Mar 13, 2020

Short description

gRPC Metadata (implemented as HTTP headers/trailers) are currently supported via the power api flag in one direction only: the server can inspect what the client sent, but there is no way for the server to pass metadata to the client (unless the implementation wants to return a gRPC error code via a rich exception).

Details

I was looking forward to try out #838 to get rid of low-level akka-http code hydrating every single response with gRPC metadata (HTTP trailer), but I could not find a hook in the generated Handlers to do so no matter what the status is - the only possibility to inject metadata being in the exception handler.

In my case, the metadata is the same across all methods of a service (so a new overload of Handler#apply with a generic => Metadata provider would do), but I can imagine some people would want to control it on per-method/request basis - this was briefly discussed in #179 (comment).

Is it worth adding opening a (small) PR with a new Handler#apply or should we consider changing (before 1.0) the return type of power api traits to return both a response and metadata?

Happy to read your thoughts!

@raboof raboof added the server label Mar 18, 2020
@raboof
Copy link
Member

raboof commented Mar 18, 2020

In my case, the metadata is the same across all methods of a service

Hmm, in that case it sounds fine to do it at the Akka HTTP level - perhaps we could provide some API's to make that easier. Putting it into the apply of the Handler is one option, but I wonder if we can make it even nicer by composing/wrapping the returned handler.

I can imagine some people would want to control it on per-method/request basis

I can also imagine this, but on the other hand we have seen relatively few actual real-life use cases for this in practice. It would make the power API's harder to use (returning a Future[Metadata, Future[Result]]?). Perhaps we should have an independent 'power option' for the request and the response?

@bjaglin
Copy link
Contributor Author

bjaglin commented Mar 25, 2020

Hmm, in that case it sounds fine to do it at the Akka HTTP level - perhaps we could provide some API's to make that easier. Putting it into the apply of the Handler is one option, but I wonder if we can make it even nicer by composing/wrapping the returned handler.

Interestingly, #887 does look like a generalization of this idea.

@justinpermar
Copy link

+1 we need this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants