Skip to content

Commit

Permalink
chore(deps): update tower to 0.5 and move tower_compat to salvo_extra (
Browse files Browse the repository at this point in the history
…#866)

* chore(deps): update tower requirement from 0.4 to 0.5

* Move tower compat to salvo_extra

* fix doc

* fix ci
  • Loading branch information
chrislearn authored Aug 13, 2024
1 parent ccae258 commit f063755
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ tokio-openssl = "0.6"
tokio-stream = { version = "0.1", default-features = false }
tokio-tungstenite = { version = "0.23", default-features = false }
tokio-util = "0.7"
tower = { version = "0.4", default-features = false }
tower = { version = "0.5", default-features = false }
tracing-subscriber = { version = "0.3" }
tracing = "0.1"
tracing-test = "0.2.1"
Expand Down
5 changes: 1 addition & 4 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["cookie", "fix-http1-request-uri", "server", "server-handle", "http1", "http2", "test", "ring"]
full = ["cookie", "fix-http1-request-uri", "server", "http1", "http2", "http2-cleartext", "quinn", "rustls", "native-tls", "openssl", "unix", "test", "tower-compat", "anyhow", "eyre", "ring", "socket2"]
full = ["cookie", "fix-http1-request-uri", "server", "http1", "http2", "http2-cleartext", "quinn", "rustls", "native-tls", "openssl", "unix", "test", "anyhow", "eyre", "ring", "socket2"]
cookie = ["dep:cookie"]
fix-http1-request-uri = ["http1"]
server = []
Expand All @@ -33,7 +33,6 @@ unix = ["http1"]
test = ["dep:brotli", "dep:flate2", "dep:zstd", "dep:encoding_rs", "dep:serde_urlencoded", "dep:url", "tokio/macros"]
acme = ["http1", "http2", "hyper-util/http1", "hyper-util/http2", "hyper-util/client-legacy", "dep:hyper-rustls", "dep:rcgen", "dep:ring", "ring", "dep:x509-parser", "dep:tokio-rustls", "dep:rustls-pemfile"]
socket2 = ["dep:socket2"]
tower-compat = ["dep:tower"]
# aws-lc-rs = ["hyper-rustls?/aws-lc-rs", "tokio-rustls?/aws-lc-rs"]
ring = ["hyper-rustls?/ring", "tokio-rustls?/ring"]

Expand Down Expand Up @@ -86,7 +85,6 @@ tokio-native-tls = { workspace = true, optional = true }
tokio-openssl = { workspace = true, optional = true }
tokio-rustls = { workspace = true, optional = true, features = ["logging", "tls12"]}
tokio-util = { workspace = true, features = ["io"] }
tower = { workspace = true, optional = true, default-features = false, features = ["buffer", "util"] }
tracing = { workspace = true }
url = { workspace = true, optional = true }
x509-parser = { workspace = true, optional = true }
Expand All @@ -100,7 +98,6 @@ nix = { workspace = true, features = ["fs", "user"] }

[dev-dependencies]
fastrand = { workspace = true }
tower = { workspace = true, features = ["limit"]}

[lints]
workspace = true
10 changes: 0 additions & 10 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! | `openssl` | TLS built on [`openssl-tls`](https://crates.io/crates/openssl) | ❌ |
//! | `native-tls` | TLS built on [`native-tls`](https://crates.io/crates/native-tls) | ❌ |
//! | `unix` | Listener based on unix socket | ❌ |
//! | `tower-compat` | Adapters for `tower::Layer` and `tower::Service` | ❌ |
//! | `anyhow` | Integrate with the [`anyhow`](https://crates.io/crates/anyhow) crate | ❌ |
//! | `eyre` | Integrate with the [`eyre`](https://crates.io/crates/eyre) crate | ❌ |
#![doc(html_favicon_url = "https://salvo.rs/favicon-32x32.png")]
Expand Down Expand Up @@ -67,11 +66,6 @@ cfg_feature! {
#![feature ="quinn"]
pub use proto::webtransport;
}
cfg_feature! {
#![feature ="tower-compat"]
pub mod tower_compat;
pub use tower_compat::{TowerServiceCompat, TowerLayerCompat};
}

pub use self::conn::Listener;
pub use self::depot::Depot;
Expand Down Expand Up @@ -116,10 +110,6 @@ pub mod prelude {
#![unix]
pub use crate::conn::UnixListener;
}
cfg_feature! {
#![feature ="tower-compat"]
pub use crate::tower_compat::{TowerServiceCompat, TowerLayerCompat};
}
pub use crate::conn::{JoinedListener, Listener, TcpListener};
pub use crate::handler::{self, Handler};
pub use crate::routing::{FlowCtrl, Router};
Expand Down
8 changes: 6 additions & 2 deletions crates/extra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["full"]
full = ["affix", "basic-auth", "caching-headers", "catch-panic", "force-https", "logging", "sse", "concurrency-limiter", "size-limiter", "trailing-slash", "timeout", "websocket", "request-id"]
full = ["affix", "basic-auth", "caching-headers", "catch-panic", "force-https", "logging", "sse", "concurrency-limiter", "size-limiter", "trailing-slash", "timeout", "websocket", "request-id", "tower-compat"]
affix = []
basic-auth = ["dep:base64"]
caching-headers = ["dep:etag", "dep:tracing"]
Expand All @@ -31,11 +31,13 @@ trailing-slash = ["dep:tracing"]
timeout = ["tokio/macros"]
websocket = ["dep:futures-util", "dep:hyper", "tokio", "tokio-tungstenite", "dep:tracing"]
request-id = ["dep:ulid"]
tower-compat = ["dep:futures-util", "dep:http-body-util", "dep:tower", "dep:tracing"]

[dependencies]
base64 = { workspace = true, optional = true }
etag = { workspace = true, features = ["std"], optional = true }
futures-util = { workspace = true, optional = true }
http-body-util = { workspace = true, optional = true }
hyper = { workspace = true, features = ["server", "http1", "http2", "client"], optional = true }
pin-project = { workspace = true, optional = true }
salvo_core = { workspace = true }
Expand All @@ -44,13 +46,15 @@ serde_json = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
tokio-tungstenite = { workspace = true, optional = true }
tokio-util = { workspace = true, features = ["io"], optional = true }
tower = { workspace = true, optional = true, default-features = false, features = ["buffer", "util"] }
tracing = { workspace = true, optional = true }
ulid = { workspace = true, optional = true, features = ["std"] }

[dev-dependencies]
salvo_core = { workspace = true, features = ["http1", "test"] }
salvo_core = { workspace = true, features = ["http1", "server", "test"] }
time = { workspace = true }
tokio-stream = { workspace = true }
tower = { workspace = true, features = ["limit"]}
tracing-test = { workspace = true }
http-body-util = { workspace = true }

Expand Down
6 changes: 6 additions & 0 deletions crates/extra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//! | [`sse`] | Server-Sent Events (SSE) middleware |
//! | [`timeout`] | Middleware for setting a timeout |
//! | [`trailing-slash`](trailing_slash) | Middleware for handling trailing slashes |
//! | [`tower-compat`](tower_compat) | Adapters for `tower::Layer` and `tower::Service` |
//! | [`websocket`] | WebSocket implementation |
#![doc(html_favicon_url = "https://salvo.rs/favicon-32x32.png")]
#![doc(html_logo_url = "https://salvo.rs/images/logo.svg")]
Expand Down Expand Up @@ -84,3 +85,8 @@ cfg_feature! {
#![feature = "request-id"]
pub mod request_id;
}
cfg_feature! {
#![feature ="tower-compat"]
pub mod tower_compat;
pub use tower_compat::{TowerServiceCompat, TowerLayerCompat};
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Adapters for [`tower::Layer`](https://docs.rs/tower/latest/tower/trait.Layer.html) and
//! [`tower::Service`](https://docs.rs/tower/latest/tower/trait.Service.html).
//!
//!
//! # Example
//!
//! ```no_run
//! use salvo_core::prelude::*;
//! use salvo_extra::tower_compat::*;
//! use tokio::time::Duration;
//! use tower::limit::RateLimitLayer;
//!
Expand Down Expand Up @@ -35,8 +36,8 @@ use hyper::body::{Body, Bytes};
use tower::buffer::Buffer;
use tower::{Layer, Service, ServiceExt};

use crate::http::{ReqBody, ResBody, StatusError};
use crate::{async_trait, Depot, FlowCtrl, Handler, Request, Response};
use salvo_core::http::{ReqBody, ResBody, StatusError};
use salvo_core::{async_trait, hyper, Depot, FlowCtrl, Handler, Request, Response};

/// Trait for tower service compat.
pub trait TowerServiceCompat<QB, SB, E, Fut> {
Expand Down Expand Up @@ -191,7 +192,7 @@ pub trait TowerLayerCompat {
impl<T> TowerLayerCompat for T where T: Layer<FlowCtrlService> + Send + Sync + Sized + 'static {}

/// Tower service compat handler.
pub struct TowerLayerHandler<Svc: Service<hyper::Request<QB>>, QB>(Buffer<Svc, hyper::Request<QB>>);
pub struct TowerLayerHandler<Svc: Service<hyper::Request<QB>>, QB>(Buffer<hyper::Request<QB>, Svc::Future>);

#[async_trait]
impl<Svc, QB, SB, E> Handler for TowerLayerHandler<Svc, QB>
Expand Down Expand Up @@ -262,8 +263,8 @@ where
mod tests {

use super::*;
use crate::test::{ResponseExt, TestClient};
use crate::{handler, Router};
use salvo_core::test::{ResponseExt, TestClient};
use salvo_core::{handler, Router};

#[tokio::test]
async fn test_tower_layer() {
Expand Down
2 changes: 1 addition & 1 deletion crates/salvo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ openssl = ["salvo_core/openssl"]
unix = ["salvo_core/unix"]
acme = ["salvo_core/acme"]
socket2 = ["salvo_core/socket2"]
tower-compat = ["salvo_core/tower-compat"]
anyhow = ["salvo_core/anyhow"]
eyre = ["salvo_core/eyre"]
test = ["salvo_core/test"]
Expand All @@ -60,6 +59,7 @@ timeout = ["salvo_extra/timeout"]
websocket = ["salvo_extra/websocket"]
request-id = ["salvo_extra/request-id"]
caching-headers = ["salvo_extra/caching-headers"]
tower-compat = ["salvo_extra/tower-compat"]
cache = ["dep:salvo-cache"]
cors = ["dep:salvo-cors"]
csrf = ["dep:salvo-csrf"]
Expand Down
4 changes: 4 additions & 0 deletions crates/salvo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ pub mod prelude {
#![feature ="timeout"]
pub use salvo_extra::timeout::Timeout;
}
cfg_feature! {
#![feature ="tower-compat"]
pub use salvo_extra::tower_compat::{TowerServiceCompat, TowerLayerCompat};
}
cfg_feature! {
#![feature ="websocket"]
pub use salvo_extra::websocket::WebSocketUpgrade;
Expand Down

0 comments on commit f063755

Please sign in to comment.