Skip to content

Commit 6a213e9

Browse files
authored
chore(router): Remove wrapper type for axum router (#1746)
1 parent 5d7bfc2 commit 6a213e9

File tree

2 files changed

+3
-32
lines changed

2 files changed

+3
-32
lines changed

tonic/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ prost = ["dep:prost"]
3131
tls = ["dep:rustls-pemfile", "dep:tokio-rustls", "dep:tokio", "tokio?/rt", "tokio?/macros"]
3232
tls-roots = ["tls", "channel", "dep:rustls-native-certs"]
3333
tls-webpki-roots = ["tls", "channel", "dep:webpki-roots"]
34-
router = ["dep:axum"]
34+
router = ["dep:axum", "dep:tower", "tower?/util"]
3535
server = [
3636
"router",
3737
"dep:async-stream",

tonic/src/service/router.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
pin::Pin,
1313
task::{ready, Context, Poll},
1414
};
15-
use tower_service::Service;
15+
use tower::{Service, ServiceExt};
1616

1717
/// A [`Service`] router.
1818
#[derive(Debug, Default, Clone)]
@@ -77,7 +77,7 @@ impl Routes {
7777
{
7878
self.router = self.router.route_service(
7979
&format!("/{}/*rest", S::NAME),
80-
AxumBodyService { service: svc },
80+
svc.map_request(|req: Request<axum::body::Body>| req.map(boxed)),
8181
);
8282
self
8383
}
@@ -143,32 +143,3 @@ impl Future for RoutesFuture {
143143
}
144144
}
145145
}
146-
147-
#[derive(Clone)]
148-
struct AxumBodyService<S> {
149-
service: S,
150-
}
151-
152-
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
153-
154-
impl<S> Service<Request<axum::body::Body>> for AxumBodyService<S>
155-
where
156-
S: Service<Request<BoxBody>, Response = Response<BoxBody>, Error = Infallible>
157-
+ Clone
158-
+ Send
159-
+ 'static,
160-
S::Future: Send + 'static,
161-
{
162-
type Response = Response<axum::body::Body>;
163-
type Error = Infallible;
164-
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
165-
166-
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
167-
self.service.poll_ready(cx)
168-
}
169-
170-
fn call(&mut self, req: Request<axum::body::Body>) -> Self::Future {
171-
let fut = self.service.call(req.map(boxed));
172-
Box::pin(async move { fut.await.map(|res| res.map(axum::body::Body::new)) })
173-
}
174-
}

0 commit comments

Comments
 (0)