Open sfackler opened 2 years ago
Agreed we can make this change. I believe we should do this in conjunction with https://github.com/hyperium/tonic/pull/830
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).
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
.
You can install layers between hyper and the tonic service that change the body type.
Yes that's what I meant.
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.
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?
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.