Skip to content

Conversation

@bouk
Copy link

@bouk bouk commented Apr 20, 2023

This allows applying the GrpcWebLayer to any kind of Service, not just ones that tonic generates. This makes it possible to use tonic-web as a grpc-web proxy to a gRPC server implemented in another language for example.

Motivation

See #1361

Solution

I made GrpcWebService generic over the request body it receives and the body that the upstream service responds. It's mostly a lot of search and replace with a couple of changes in how we convert the body to conform to the right interface.

I've also added a test that proxies to a gRPC service over a hyper::Client to show it's generic over any kind of Service.

Closes #1361

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the change looks good to me, I left some comments. I am not super happy without this makes the router stuff a bit more complicated but I don't think we have another option.

ResponseFuture {
case: Case::Other {
future: self.inner.call(req),
future: self.inner.call(req.map(box_body)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might be able to avoid the box if we become more generic over the incoming body type in the middleware?

Copy link
Author

@bouk bouk Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's unavoidable because the middleware constructs its own bodies when it decodes the request.

the alternative would be an enum of the request body and whatever we create in GrpcWebCall I guess? Maybe that's not too bad.

@bouk
Copy link
Author

bouk commented Apr 20, 2023

@LucioFranco thanks for the quick review, I'll make the changes tomorrow. I'll see if I can make it backwards-compatible.

@bouk bouk requested a review from LucioFranco April 21, 2023 09:32
@bouk
Copy link
Author

bouk commented Apr 21, 2023

@LucioFranco Please take another look

  1. I've tried to keep it backwards-compatible by adding default type parameters
  2. I un-exposed the axum IntoResponse trait by making the ResBody of the router a bit more constrained
  3. I addressed some of your comments

@bouk
Copy link
Author

bouk commented May 8, 2023

@LucioFranco could you take another look at this?

@bouk bouk force-pushed the grpc-web-anything branch from 7d16f79 to 4b1968b Compare May 10, 2023 15:17
@bouk bouk force-pushed the grpc-web-anything branch 2 times, most recently from 013d34b to 3d6121e Compare September 14, 2023 10:49
This allows applying the GrpcWebLayer to any kind of Service, not just
ones that tonic generates. This makes it possible to use tonic-web as a
grpc-web proxy to a gRPC implemented in another language for example.
@bouk bouk force-pushed the grpc-web-anything branch from 101fe16 to 4126d68 Compare September 14, 2023 11:22
@bouk
Copy link
Author

bouk commented Sep 14, 2023

Hi @LucioFranco I'm still interested in landing this, just rebased on master could you take another look?

@bouk
Copy link
Author

bouk commented Jun 13, 2024

Since tonic has been upgraded to http v1 this will obviously need a rebase, which I'll do in a new PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make tonic-web layer generic over request/response body

2 participants