Skip to content

Commit

Permalink
chore: Update to tower 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Sep 20, 2024
1 parent 43c926f commit b9781f2
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 24 deletions.
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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]
Expand Down
1 change: 0 additions & 1 deletion examples/src/tls_rustls/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! This examples shows how you can combine `hyper-rustls` and `tonic` to
//! provide a custom `ClientConfig` for the tls configuration.

pub mod pb {
tonic::include_proto!("/grpc.examples.unaryecho");
}
Expand Down
2 changes: 1 addition & 1 deletion interop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions tests/compression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
4 changes: 2 additions & 2 deletions tests/integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion tonic-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions tonic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tonic/src/transport/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Future<Output = T> + Send + 'a>>;
type Svc = Either<Connection, BoxService<Request<BoxBody>, Response<BoxBody>, crate::Error>>;

const DEFAULT_BUFFER_SIZE: usize = 1024;

Expand Down Expand Up @@ -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, Request<BoxBody>>,
svc: Buffer<Request<BoxBody>, BoxFuture<'static, Result<Response<BoxBody>, 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<<Svc as Service<Request<BoxBody>>>::Future>,
inner: BufferResponseFuture<BoxFuture<'static, Result<Response<BoxBody>, crate::Error>>>,
}

impl Channel {
Expand Down Expand Up @@ -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 }
Expand All @@ -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 })
Expand All @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,10 @@ where
.layer(BoxCloneService::layer())
.map_request(move |mut request: Request<BoxBody>| {
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());
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/transport/server/service/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl<IO> ServerIo<IO> {
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()),
}
}
}
Expand Down

0 comments on commit b9781f2

Please sign in to comment.