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

Router should support request body types other than hyper::Body #905

Open
sfackler opened this issue Feb 3, 2022 · 7 comments
Open

Router should support request body types other than hyper::Body #905

sfackler opened this issue Feb 3, 2022 · 7 comments

Comments

@sfackler
Copy link

sfackler commented Feb 3, 2022

The generated server Service implementations already support arbitrary request body types, but Router is currently hardcoded to work with hyper::Body directly. It'd be great if that were relaxed to work with any suitable body type.

@LucioFranco
Copy link
Member

Agreed we can make this change. I believe we should do this in conjunction with #830

@LucioFranco LucioFranco added this to the 0.7 milestone Feb 16, 2022
@LucioFranco LucioFranco removed this from the 0.7 milestone Mar 31, 2022
@LucioFranco
Copy link
Member

I am going to remove this from 0.7 because it will be quite challenging to get this change in right now and I would actually like to refactor the transport module in the next release (aka remove it and re do it).

@davidpdrsn
Copy link
Member

Is it actually possible? Hyper requires services accept Request<hyper::Body>. You can change the body in a middleware but the top level body must be hyper::Body.

@sfackler
Copy link
Author

You can install layers between hyper and the tonic service that change the body type.

@davidpdrsn
Copy link
Member

Yes that's what I meant.

@sfackler
Copy link
Author

sfackler commented Mar 31, 2022

So then it's totally possible to create a Hyper service that changes the request body type and then feeds that modified body type into the Tonic Router, except that Router won't let you do that.

@tobz
Copy link
Collaborator

tobz commented May 27, 2022

This would be extremely helpful for a particular issue I'm working on. As @sfackler points out, the major sticking point seems to be where tonic meets axum. Without this, the only current workaround is doing very goofy stuff like getting a channel-backed hyper::Body, even if you only needed to do something like count the number of bytes per data chunk emitted by the body, etc.

I'd be interested in trying to work on/submit a PR for this. Is this something you'd be receptive to, given the thoughts/plans around breaking tonic apart into more composable chunks?

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

No branches or pull requests

4 participants