diff --git a/examples/Cargo.toml b/examples/Cargo.toml index faf296a98..c1cf4dee4 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -263,11 +263,27 @@ path = "src/codec_buffers/client.rs" [features] gcp = ["dep:prost-types", "tonic/tls"] -routeguide = ["dep:async-stream", "tokio-stream", "dep:rand", "dep:serde", "dep:serde_json"] +routeguide = [ + "dep:async-stream", + "tokio-stream", + "dep:rand", + "dep:serde", + "dep:serde_json", +] reflection = ["dep:tonic-reflection"] autoreload = ["tokio-stream/net", "dep:listenfd"] health = ["dep:tonic-health"] -grpc-web = ["dep:tonic-web", "dep:bytes", "dep:http", "dep:hyper", "dep:hyper-util", "dep:tracing-subscriber", "dep:tower", "dep:tower-http", "tower-http?/cors"] +grpc-web = [ + "dep:tonic-web", + "dep:bytes", + "dep:http", + "dep:hyper", + "dep:hyper-util", + "dep:tracing-subscriber", + "dep:tower", + "dep:tower-http", + "tower-http?/cors", +] tracing = ["dep:tracing", "dep:tracing-subscriber"] uds = ["tokio-stream/net", "dep:tower", "dep:hyper", "dep:hyper-util"] streaming = ["tokio-stream", "dep:h2"] @@ -276,7 +292,19 @@ tower = ["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:tower", + "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"] @@ -284,7 +312,29 @@ types = ["dep:tonic-types"] h2c = ["dep:hyper", "dep:tower", "dep:http", "dep:hyper-util"] cancellation = ["dep:tokio-util"] -full = ["gcp", "routeguide", "reflection", "autoreload", "health", "grpc-web", "tracing", "uds", "streaming", "mock", "tower", "json-codec", "compression", "tls", "tls-rustls", "dynamic-load-balance", "timeout", "tls-client-auth", "types", "cancellation", "h2c"] +full = [ + "gcp", + "routeguide", + "reflection", + "autoreload", + "health", + "grpc-web", + "tracing", + "uds", + "streaming", + "mock", + "tower", + "json-codec", + "compression", + "tls", + "tls-rustls", + "dynamic-load-balance", + "timeout", + "tls-client-auth", + "types", + "cancellation", + "h2c", +] default = ["full"] [dependencies] @@ -300,12 +350,15 @@ 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.1", optional = true } rand = { version = "0.8", optional = true } serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } tracing = { version = "0.1.16", optional = true } -tracing-subscriber = { version = "0.3", features = ["tracing-log", "fmt"], optional = true } +tracing-subscriber = { version = "0.3", features = [ + "tracing-log", + "fmt", +], optional = true } prost-types = { version = "0.13", optional = true } http = { version = "1", optional = true } http-body = { version = "1", optional = true } @@ -315,10 +368,17 @@ hyper-util = { version = "0.1.4", optional = true } listenfd = { version = "1.0", optional = true } bytes = { version = "1", optional = true } 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 } +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.1", optional = true } pin-project = { version = "1.0.11", optional = true } [build-dependencies] diff --git a/tests/compression/Cargo.toml b/tests/compression/Cargo.toml index a40522fa6..abf078e96 100644 --- a/tests/compression/Cargo.toml +++ b/tests/compression/Cargo.toml @@ -16,11 +16,14 @@ hyper-util = "0.1" paste = "1.0.12" pin-project = "1.0" prost = "0.13" -tokio = {version = "1.0", features = ["macros", "rt-multi-thread", "net"]} +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"]} +tonic = { path = "../../tonic", features = ["gzip", "zstd"] } +tower = { version = "0.5.1", features = [] } +tower-http = { version = "0.6.1", features = [ + "map-response-body", + "map-request-body", +] } [build-dependencies] -tonic-build = {path = "../../tonic-build" } +tonic-build = { path = "../../tonic-build" } diff --git a/tests/compression/src/lib.rs b/tests/compression/src/lib.rs index 02f729b60..b32d3c0a5 100644 --- a/tests/compression/src/lib.rs +++ b/tests/compression/src/lib.rs @@ -15,7 +15,7 @@ use tonic::{ transport::{Channel, Endpoint, Server, Uri}, Request, Response, Status, Streaming, }; -use tower::{layer::layer_fn, service_fn, Service, ServiceBuilder}; +use tower::{layer::layer_fn, Service, ServiceBuilder}; use tower_http::{map_request_body::MapRequestBodyLayer, map_response_body::MapResponseBodyLayer}; mod bidirectional_stream; diff --git a/tests/compression/src/util.rs b/tests/compression/src/util.rs index d7e250ce4..2b474512e 100644 --- a/tests/compression/src/util.rs +++ b/tests/compression/src/util.rs @@ -138,7 +138,7 @@ pub async fn mock_io_channel(client: tokio::io::DuplexStream) -> Channel { Endpoint::try_from("http://[::]:50051") .unwrap() - .connect_with_connector(service_fn(move |_: Uri| { + .connect_with_connector(tower::service_fn(move |_: Uri| { let client = TokioIo::new(client.take().unwrap()); async move { Ok::<_, std::io::Error>(client) } })) diff --git a/tests/integration_tests/Cargo.toml b/tests/integration_tests/Cargo.toml index 238fe374d..f4170efa9 100644 --- a/tests/integration_tests/Cargo.toml +++ b/tests/integration_tests/Cargo.toml @@ -11,20 +11,25 @@ version = "0.1.0" [dependencies] bytes = "1.0" prost = "0.13" -tokio = {version = "1.0", features = ["macros", "rt-multi-thread", "net", "sync"]} -tonic = {path = "../../tonic"} -tracing-subscriber = {version = "0.3"} +tokio = { version = "1.0", features = [ + "macros", + "rt-multi-thread", + "net", + "sync", +] } +tonic = { path = "../../tonic" } +tracing-subscriber = { version = "0.3" } [dev-dependencies] async-stream = "0.3" http = "1" http-body = "1" hyper-util = "0.1" -tokio-stream = {version = "0.1.5", features = ["net"]} -tower = {version = "0.4", features = []} +tokio-stream = { version = "0.1.5", features = ["net"] } +tower = { version = "0.5.1", features = [] } tower-http = { version = "0.5", features = ["set-header", "trace"] } tower-service = "0.3" tracing = "0.1" [build-dependencies] -tonic-build = {path = "../../tonic-build"} +tonic-build = { path = "../../tonic-build" } diff --git a/tests/integration_tests/tests/connect_info.rs b/tests/integration_tests/tests/connect_info.rs index e87bb858f..b85d30cd7 100644 --- a/tests/integration_tests/tests/connect_info.rs +++ b/tests/integration_tests/tests/connect_info.rs @@ -63,7 +63,6 @@ pub mod unix { transport::{server::UdsConnectInfo, Endpoint, Server, Uri}, Request, Response, Status, }; - use tower::service_fn; use integration_tests::pb::{test_client, test_server, Input, Output}; @@ -109,7 +108,7 @@ pub mod unix { let path = unix_socket_path.clone(); let channel = Endpoint::try_from("http://[::]:50051") .unwrap() - .connect_with_connector(service_fn(move |_: Uri| { + .connect_with_connector(tower::service_fn(move |_: Uri| { let path = path.clone(); async move { Ok::<_, io::Error>(TokioIo::new(UnixStream::connect(path).await?)) } })) diff --git a/tonic-web/Cargo.toml b/tonic-web/Cargo.toml index 85e5ccb9c..7ec6297df 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.1", features = ["cors"] } tracing = "0.1" [dev-dependencies] diff --git a/tonic/Cargo.toml b/tonic/Cargo.toml index 15f3dc49e..0dd1a0d20 100644 --- a/tonic/Cargo.toml +++ b/tonic/Cargo.toml @@ -28,8 +28,16 @@ gzip = ["dep:flate2"] zstd = ["dep:zstd"] default = ["transport", "codegen", "prost"] prost = ["dep:prost"] -tls = ["dep:rustls-pemfile", "dep:tokio-rustls", "dep:tokio", "tokio?/rt", "tokio?/macros"] -tls-roots = ["tls-native-roots"] # Deprecated. Please use `tls-native-roots` instead. +tls = [ + "dep:rustls-pemfile", + "dep:tokio-rustls", + "dep:tokio", + "tokio?/rt", + "tokio?/macros", +] +tls-roots = [ + "tls-native-roots", +] # Deprecated. Please use `tls-native-roots` instead. tls-native-roots = ["tls", "channel", "dep:rustls-native-certs"] tls-webpki-roots = ["tls", "channel", "dep:webpki-roots"] router = ["dep:axum", "dep:tower", "tower?/util"] @@ -37,18 +45,34 @@ server = [ "router", "dep:async-stream", "dep:h2", - "dep:hyper", "hyper?/server", - "dep:hyper-util", "hyper-util?/service", "hyper-util?/server-auto", + "dep:hyper", + "hyper?/server", + "dep:hyper-util", + "hyper-util?/service", + "hyper-util?/server-auto", "dep:socket2", - "dep:tokio", "tokio?/macros", "tokio?/net", "tokio?/time", + "dep:tokio", + "tokio?/macros", + "tokio?/net", + "tokio?/time", "tokio-stream/net", - "dep:tower", "tower?/util", "tower?/limit", + "dep:tower", + "tower?/util", + "tower?/limit", ] channel = [ - "dep:hyper", "hyper?/client", - "dep:hyper-util", "hyper-util?/client-legacy", - "dep:tower", "tower?/balance", "tower?/buffer", "tower?/discover", "tower?/limit", "tower?/util", - "dep:tokio", "tokio?/time", + "dep:hyper", + "hyper?/client", + "dep:hyper-util", + "hyper-util?/client-legacy", + "dep:tower", + "tower?/balance", + "tower?/buffer", + "tower?/discover", + "tower?/limit", + "tower?/util", + "dep:tokio", + "tokio?/time", "dep:hyper-timeout", ] transport = ["server", "channel"] @@ -69,36 +93,42 @@ percent-encoding = "2.1" pin-project = "1.0.11" tower-layer = "0.3" tower-service = "0.3" -tokio-stream = {version = "0.1.16", default-features = false} +tokio-stream = { version = "0.1.16", default-features = false } # prost -prost = {version = "0.13", default-features = false, features = ["std"], optional = true} +prost = { version = "0.13", default-features = false, features = [ + "std", +], optional = true } # codegen -async-trait = {version = "0.1.13", optional = true} +async-trait = { version = "0.1.13", optional = true } # transport -async-stream = {version = "0.3", optional = true} -h2 = {version = "0.4", optional = true} -hyper = {version = "1", features = ["http1", "http2"], optional = true} +async-stream = { version = "0.3", optional = true } +h2 = { version = "0.4", optional = true } +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} -axum = {version = "0.7", default-features = false, optional = true} +tokio = { version = "1", default-features = false, optional = true } +tower = { version = "0.5.1", default-features = false, optional = true } +axum = { version = "0.7", default-features = false, optional = true } # rustls rustls-pemfile = { version = "2.0", optional = true } rustls-native-certs = { version = "0.8", optional = true } -tokio-rustls = { version = "0.26", default-features = false, features = ["logging", "tls12", "ring"], optional = true } +tokio-rustls = { version = "0.26", default-features = false, features = [ + "logging", + "tls12", + "ring", +], optional = true } webpki-roots = { version = "0.26", optional = true } # compression -flate2 = {version = "1.0", optional = true} +flate2 = { version = "1.0", optional = true } zstd = { version = "0.13.0", optional = true } # channel -hyper-timeout = {version = "0.5", optional = true} +hyper-timeout = { version = "0.5", optional = true } [dev-dependencies] bencher = "0.1.5" @@ -106,8 +136,8 @@ quickcheck = "1.0" 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"]} +tokio = { version = "1.0", features = ["rt", "macros"] } +tower = { version = "0.5.1", 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..e0a0f7b41 100644 --- a/tonic/src/transport/channel/mod.rs +++ b/tonic/src/transport/channel/mod.rs @@ -31,15 +31,16 @@ 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; +type ChannelFuture = BoxFuture<'static, Result, crate::Error>>; + /// A default batteries included `transport` channel. /// /// This provides a fully featured http2 gRPC client based on `hyper` @@ -65,14 +66,14 @@ const DEFAULT_BUFFER_SIZE: usize = 1024; /// cloning the `Channel` type is cheap and encouraged. #[derive(Clone)] pub struct Channel { - svc: Buffer>, + svc: Buffer, ChannelFuture>, } /// 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, } impl Channel { @@ -156,7 +157,7 @@ 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()), } } }