From 58345a6bf29b4c17eccc949dd6d7640928dff0cc Mon Sep 17 00:00:00 2001 From: tottoto Date: Fri, 18 Oct 2024 02:48:53 +0900 Subject: [PATCH] chore: Update to tower 0.5 (#1892) --- examples/Cargo.toml | 4 ++-- interop/Cargo.toml | 2 +- tests/compression/Cargo.toml | 4 ++-- tests/integration_tests/Cargo.toml | 4 ++-- tonic-web/Cargo.toml | 2 +- tonic/Cargo.toml | 4 ++-- tonic/src/transport/channel/mod.rs | 16 ++++++++-------- tonic/src/transport/server/mod.rs | 4 ++-- tonic/src/transport/server/service/io.rs | 4 ++-- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index faf296a98..d6cc1b5c6 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -300,7 +300,7 @@ 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 } rand = { version = "0.8", optional = true } serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } @@ -318,7 +318,7 @@ h2 = { version = "0.4", optional = true } tokio-rustls = { version = "0.26", optional = true, features = ["ring", "tls12"], default-features = false } hyper-rustls = { version = "0.27.0", features = ["http2", "ring", "tls12"], optional = true, default-features = false } rustls-pemfile = { version = "2.0.0", optional = true } -tower-http = { version = "0.5", optional = true } +tower-http = { version = "0.6", optional = true } pin-project = { version = "1.0.11", optional = true } [build-dependencies] 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..f9ecf1590 100644 --- a/tests/compression/Cargo.toml +++ b/tests/compression/Cargo.toml @@ -19,8 +19,8 @@ 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-http = {version = "0.5", features = ["map-response-body", "map-request-body"]} +tower = "0.5" +tower-http = {version = "0.6", features = ["map-response-body", "map-request-body"]} [build-dependencies] tonic-build = {path = "../../tonic-build" } diff --git a/tests/integration_tests/Cargo.toml b/tests/integration_tests/Cargo.toml index 238fe374d..8993723a9 100644 --- a/tests/integration_tests/Cargo.toml +++ b/tests/integration_tests/Cargo.toml @@ -21,8 +21,8 @@ http = "1" http-body = "1" hyper-util = "0.1" tokio-stream = {version = "0.1.5", features = ["net"]} -tower = {version = "0.4", features = []} -tower-http = { version = "0.5", features = ["set-header", "trace"] } +tower = "0.5" +tower-http = { version = "0.6", features = ["set-header", "trace"] } tower-service = "0.3" tracing = "0.1" diff --git a/tonic-web/Cargo.toml b/tonic-web/Cargo.toml index 85e5ccb9c..3cd17ec09 100644 --- a/tonic-web/Cargo.toml +++ b/tonic-web/Cargo.toml @@ -25,7 +25,7 @@ pin-project = "1" tonic = { version = "0.12", path = "../tonic", default-features = false } tower-service = "0.3" tower-layer = "0.3" -tower-http = { version = "0.5", features = ["cors"] } +tower-http = { version = "0.6", features = ["cors"] } tracing = "0.1" [dev-dependencies] diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 15f3dc49e..62df328b1 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -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 ed8d22275..d22ced98d 100644 --- a/tonic/src/transport/channel/mod.rs +++ b/tonic/src/transport/channel/mod.rs @@ -29,14 +29,13 @@ use tokio::sync::mpsc::{channel, Sender}; use hyper::rt; use tower::balance::p2c::Balance; use tower::{ - buffer::{self, Buffer}, + buffer::{future::ResponseFuture as BufferResponseFuture, 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,14 @@ 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: BufferResponseFuture, crate::Error>>>, } impl Channel { @@ -156,7 +155,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 +175,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 +191,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 25659b81b..6e1fcc461 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -1030,10 +1030,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()), } } }