diff --git a/examples/Cargo.toml b/examples/Cargo.toml index aea9133e1..646da42b6 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -276,7 +276,7 @@ tower = ["dep:hyper", "dep:hyper-util", "dep:tower", "tower?/timeout", "dep:http json-codec = ["dep:serde", "dep:serde_json", "dep:bytes"] compression = ["tonic/gzip"] tls = ["tonic/tls"] -tls-rustls = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:hyper-rustls", "dep:tower", "tower-http/util", "tower-http/add-extension", "dep:rustls-pemfile", "dep:tokio-rustls", "dep:pin-project", "dep:http-body-util"] +tls-rustls = ["dep:http", "dep:hyper", "dep:hyper-util", "dep:hyper-rustls", "dep:tower04", "tower-http/util", "tower-http/add-extension", "dep:rustls-pemfile", "dep:tokio-rustls", "dep:pin-project", "dep:http-body-util"] dynamic-load-balance = ["dep:tower"] timeout = ["tokio/time", "dep:tower", "tower?/timeout"] tls-client-auth = ["tonic/tls"] @@ -300,7 +300,8 @@ tonic-types = { path = "../tonic-types", optional = true } async-stream = { version = "0.3", optional = true } tokio-stream = { version = "0.1", optional = true } tokio-util = { version = "0.7.8", optional = true } -tower = { version = "0.4", optional = true } +tower = { version = "0.5", optional = true } +tower04 = { package = "tower", version = "0.4", optional = true } rand = { version = "0.8", optional = true } serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } diff --git a/examples/src/tls_rustls/client.rs b/examples/src/tls_rustls/client.rs index 47c7d7298..a5027cfa6 100644 --- a/examples/src/tls_rustls/client.rs +++ b/examples/src/tls_rustls/client.rs @@ -1,5 +1,6 @@ //! This examples shows how you can combine `hyper-rustls` and `tonic` to //! provide a custom `ClientConfig` for the tls configuration. +use tower04 as tower; pub mod pb { tonic::include_proto!("/grpc.examples.unaryecho"); diff --git a/examples/src/tls_rustls/server.rs b/examples/src/tls_rustls/server.rs index 7cc464572..684cdcc3b 100644 --- a/examples/src/tls_rustls/server.rs +++ b/examples/src/tls_rustls/server.rs @@ -1,3 +1,5 @@ +use tower04 as tower; + pub mod pb { tonic::include_proto!("/grpc.examples.unaryecho"); } diff --git a/interop/Cargo.toml b/interop/Cargo.toml index 5ec668f4f..9314cb40a 100644 --- a/interop/Cargo.toml +++ b/interop/Cargo.toml @@ -26,7 +26,7 @@ prost = "0.13" tokio = {version = "1.0", features = ["rt-multi-thread", "time", "macros"]} tokio-stream = "0.1" tonic = {path = "../tonic", features = ["tls"]} -tower = {version = "0.4"} +tower = "0.5" tracing-subscriber = {version = "0.3"} [build-dependencies] diff --git a/tests/compression/Cargo.toml b/tests/compression/Cargo.toml index a40522fa6..b50f91796 100644 --- a/tests/compression/Cargo.toml +++ b/tests/compression/Cargo.toml @@ -19,7 +19,7 @@ prost = "0.13" tokio = {version = "1.0", features = ["macros", "rt-multi-thread", "net"]} tokio-stream = "0.1" tonic = {path = "../../tonic", features = ["gzip", "zstd"]} -tower = {version = "0.4", features = []} +tower = "0.5" tower-http = {version = "0.5", features = ["map-response-body", "map-request-body"]} [build-dependencies] diff --git a/tests/integration_tests/Cargo.toml b/tests/integration_tests/Cargo.toml index 238fe374d..b1a90d82f 100644 --- a/tests/integration_tests/Cargo.toml +++ b/tests/integration_tests/Cargo.toml @@ -21,7 +21,7 @@ http = "1" http-body = "1" hyper-util = "0.1" tokio-stream = {version = "0.1.5", features = ["net"]} -tower = {version = "0.4", features = []} +tower = "0.5" tower-http = { version = "0.5", features = ["set-header", "trace"] } tower-service = "0.3" tracing = "0.1" diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index bf32e23c1..c08ad6cfd 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -47,7 +47,7 @@ server = [ channel = [ "dep:hyper", "hyper?/client", "dep:hyper-util", "hyper-util?/client-legacy", - "dep:tower", "tower?/balance", "tower?/buffer", "tower?/discover", "tower?/limit", + "dep:tower", "tower?/balance", "tower?/buffer", "tower?/discover", "tower?/limit", "tower?/util", "dep:tokio", "tokio?/time", "dep:hyper-timeout", ] @@ -84,7 +84,7 @@ hyper = {version = "1", features = ["http1", "http2"], optional = true} hyper-util = { version = "0.1.4", features = ["tokio"], optional = true } socket2 = { version = "0.5", optional = true, features = ["all"] } tokio = {version = "1", default-features = false, optional = true} -tower = {version = "0.4.7", default-features = false, optional = true} +tower = {version = "0.5", default-features = false, optional = true} axum = {version = "0.7", default-features = false, optional = true} # rustls @@ -107,7 +107,7 @@ quickcheck_macros = "1.0" rand = "0.8" static_assertions = "1.0" tokio = {version = "1.0", features = ["rt", "macros"]} -tower = {version = "0.4.7", features = ["full"]} +tower = {version = "0.5", features = ["full"]} [package.metadata.docs.rs] all-features = true diff --git a/tonic/src/transport/channel/mod.rs b/tonic/src/transport/channel/mod.rs index 565bd2647..deca0b075 100644 --- a/tonic/src/transport/channel/mod.rs +++ b/tonic/src/transport/channel/mod.rs @@ -31,12 +31,11 @@ use tower::balance::p2c::Balance; use tower::{ buffer::{self, Buffer}, discover::{Change, Discover}, - util::{BoxService, Either}, + util::BoxService, Service, }; type BoxFuture<'a, T> = Pin + Send + 'a>>; -type Svc = Either, Response, crate::Error>>; const DEFAULT_BUFFER_SIZE: usize = 1024; @@ -65,14 +64,15 @@ const DEFAULT_BUFFER_SIZE: usize = 1024; /// cloning the `Channel` type is cheap and encouraged. #[derive(Clone)] pub struct Channel { - svc: Buffer>, + svc: Buffer, BoxFuture<'static, Result, crate::Error>>>, } /// A future that resolves to an HTTP response. /// /// This is returned by the `Service::call` on [`Channel`]. pub struct ResponseFuture { - inner: buffer::future::ResponseFuture<>>::Future>, + inner: + buffer::future::ResponseFuture, crate::Error>>>, } impl Channel { @@ -156,7 +156,8 @@ impl Channel { let executor = endpoint.executor.clone(); let svc = Connection::lazy(connector, endpoint); - let (svc, worker) = Buffer::pair(Either::A(svc), buffer_size); + let (svc, worker) = Buffer::pair(svc, buffer_size); + executor.execute(worker); Channel { svc } @@ -175,7 +176,7 @@ impl Channel { let svc = Connection::connect(connector, endpoint) .await .map_err(super::Error::from_source)?; - let (svc, worker) = Buffer::pair(Either::A(svc), buffer_size); + let (svc, worker) = Buffer::pair(svc, buffer_size); executor.execute(worker); Ok(Channel { svc }) @@ -191,7 +192,7 @@ impl Channel { let svc = Balance::new(discover); let svc = BoxService::new(svc); - let (svc, worker) = Buffer::pair(Either::B(svc), buffer_size); + let (svc, worker) = Buffer::pair(svc, buffer_size); executor.execute(Box::pin(worker)); Channel { svc } diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index 62006e1a6..5d11254e9 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -1037,10 +1037,10 @@ where .layer(BoxCloneService::layer()) .map_request(move |mut request: Request| { match &conn_info { - tower::util::Either::A(inner) => { + tower::util::Either::Left(inner) => { request.extensions_mut().insert(inner.clone()); } - tower::util::Either::B(inner) => { + tower::util::Either::Right(inner) => { #[cfg(feature = "tls")] { request.extensions_mut().insert(inner.clone()); diff --git a/tonic/src/transport/server/service/io.rs b/tonic/src/transport/server/service/io.rs index e4588abe7..bfb441e88 100644 --- a/tonic/src/transport/server/service/io.rs +++ b/tonic/src/transport/server/service/io.rs @@ -37,9 +37,9 @@ impl ServerIo { IO: Connected, { match self { - Self::Io(io) => Either::A(io.connect_info()), + Self::Io(io) => Either::Left(io.connect_info()), #[cfg(feature = "tls")] - Self::TlsIo(io) => Either::B(io.connect_info()), + Self::TlsIo(io) => Either::Right(io.connect_info()), } } }