diff --git a/examples/src/h2c/server.rs b/examples/src/h2c/server.rs index 838730f86..b9a31f604 100644 --- a/examples/src/h2c/server.rs +++ b/examples/src/h2c/server.rs @@ -4,7 +4,7 @@ use hyper_util::rt::{TokioExecutor, TokioIo}; use hyper_util::server::conn::auto::Builder; use hyper_util::service::TowerToHyperService; use tokio::net::TcpListener; -use tonic::{transport::Server, Request, Response, Status}; +use tonic::{service::Routes, Request, Response, Status}; use hello_world::greeter_server::{Greeter, GreeterServer}; use hello_world::{HelloReply, HelloRequest}; @@ -39,9 +39,7 @@ async fn main() -> Result<(), Box> { println!("GreeterServer listening on {}", addr); let incoming = TcpListener::bind(addr).await?; - let svc = Server::builder() - .add_service(GreeterServer::new(greeter)) - .into_router(); + let svc = Routes::new(GreeterServer::new(greeter)); let h2c = h2c::H2c { s: svc }; @@ -71,8 +69,8 @@ mod h2c { use http::{Request, Response}; use hyper::body::Incoming; use hyper_util::{rt::TokioExecutor, service::TowerToHyperService}; - use tonic::{body::empty_body, transport::AxumBody}; - use tower::Service; + use tonic::body::empty_body; + use tower::{Service, ServiceExt}; #[derive(Clone)] pub struct H2c { @@ -83,7 +81,10 @@ mod h2c { impl Service> for H2c where - S: Service, Response = Response> + Clone + Send + 'static, + S: Service, Response = Response> + + Clone + + Send + + 'static, S::Future: Send + 'static, S::Error: Into + Sync + Send + 'static, S::Response: Send + 'static, @@ -100,8 +101,12 @@ mod h2c { std::task::Poll::Ready(Ok(())) } - fn call(&mut self, mut req: hyper::Request) -> Self::Future { - let svc = self.s.clone(); + fn call(&mut self, req: hyper::Request) -> Self::Future { + let mut req = req.map(tonic::body::boxed); + let svc = self + .s + .clone() + .map_request(|req: Request| req.map(tonic::body::boxed)); Box::pin(async move { tokio::spawn(async move { let upgraded_io = hyper::upgrade::on(&mut req).await.unwrap(); diff --git a/tonic/src/body.rs b/tonic/src/body.rs index 428c0dade..c3d850b0f 100644 --- a/tonic/src/body.rs +++ b/tonic/src/body.rs @@ -6,7 +6,7 @@ use http_body_util::BodyExt; pub type BoxBody = http_body_util::combinators::UnsyncBoxBody; /// Convert a [`http_body::Body`] into a [`BoxBody`]. -pub(crate) fn boxed(body: B) -> BoxBody +pub fn boxed(body: B) -> BoxBody where B: http_body::Body + Send + 'static, B::Error: Into,