diff --git a/Cargo.toml b/Cargo.toml index 1bc8ed3..0b091d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,24 +14,24 @@ version = "2.5.1" [workspace.dependencies] async-trait = "0.1.88" -tokio = { version = "1.44.2", features = ["full"] } -tonic = "0.13.0" +tokio = { version = "1", features = ["full"] } +tonic = "0.13" prost = "0.13" -http = "1.3.1" -hyper-util = "0.1.11" -hyper = "1.6.0" -tower = "0.5.2" -tonic-build = "0.13.0" +http = "1" +hyper-util = "0.1" +hyper = "1" +tower = "0.5" +tonic-build = "0.13" tokio_wasi = { version = "1", features = ["full"] } -tokio-stream = { version = "0.1.17", features = ["net"] } -futures-util = "0.3.31" -once_cell = "1.21.3" -tokio-tungstenite = "0.26.2" +tokio-stream = { version = "0.1", features = ["net"] } +futures-util = "0.3" +once_cell = "1" +tokio-tungstenite = "0.26" tracing-subscriber = "0.3" -headers = "0.4.0" -serde = { version = "1.0.219", features = ["derive"] } -uuid = { version = "1.16.0", features = ["serde", "v4"] } +headers = "0.4" +serde = { version = "1", features = ["derive"] } +uuid = { version = "1", features = ["serde", "v4"] } parking_lot = "0.12" chrono = "0.4" dlopen2 = { version = "0.7.0", features = ["derive"] } -h2 = "0.4.9" +h2 = "0.4" diff --git a/benchmark/Cargo.toml b/benchmark/Cargo.toml index df45bb2..a2dd1a7 100644 --- a/benchmark/Cargo.toml +++ b/benchmark/Cargo.toml @@ -8,7 +8,7 @@ publish = false silent = { path = "../silent" } [dev-dependencies] -criterion = "0.5" +criterion = "0.6" [[bench]] name = "route_benchmark" diff --git a/examples/grpc/Cargo.toml b/examples/grpc/Cargo.toml index 3c27bbe..7388c3f 100644 --- a/examples/grpc/Cargo.toml +++ b/examples/grpc/Cargo.toml @@ -21,4 +21,4 @@ silent = { path = "../../silent", features = ["grpc"] } async-trait.workspace = true [build-dependencies] -tonic-build = { version = "0.13.0" } +tonic-build = { version = "0.13" } diff --git a/examples/grpc_streaming/Cargo.toml b/examples/grpc_streaming/Cargo.toml index 48e218a..50384ce 100644 --- a/examples/grpc_streaming/Cargo.toml +++ b/examples/grpc_streaming/Cargo.toml @@ -23,4 +23,4 @@ tokio-stream.workspace = true h2.workspace = true [build-dependencies] -tonic-build = { version = "0.13.0" } +tonic-build = { version = "0.13" } diff --git a/examples/tls/Cargo.toml b/examples/tls/Cargo.toml index b664341..a2c6a77 100644 --- a/examples/tls/Cargo.toml +++ b/examples/tls/Cargo.toml @@ -10,4 +10,4 @@ publish = false silent = { path = "../../silent", features = ["tls"] } tokio = { version = "1", features = ["full"] } tokio-rustls = { version = "0.26.2" } -rustls = { version = "0.23.26" } +rustls = { version = "0.23" } diff --git a/silent/Cargo.toml b/silent/Cargo.toml index cf94f86..a5efa93 100644 --- a/silent/Cargo.toml +++ b/silent/Cargo.toml @@ -35,61 +35,61 @@ tls = ["dep:tokio-rustls"] [dependencies] # Basic dependencies -thiserror = "2.0.12" -hyper = { version = "1.6.0", features = ["full"] } -hyper-util = { version = "0.1.11", features = ["server-auto", "tokio"] } -tokio = { version = "1.44.2", optional = true } -bytes = "1.10.1" -http-body-util = "0.1.3" -tracing = "0.1.41" -tracing-subscriber = { version = "0.3.19", features = ["chrono"] } -async-trait = "0.1.88" -serde = { version = "1.0.219", features = ["derive"] } -serde_json = "1.0.140" -uuid = "1.16.0" -url = "2.5.4" -serde_html_form = "0.2.7" -mime = "0.3.17" -futures-util = "0.3.31" -chrono = { version = "0.4.40", default-features = false, features = ["clock"] } -tokio-tungstenite = { version = "0.26.2", optional = true } -headers = "0.4.0" -tokio-stream = { version = "0.1.17", features = ["net"], optional = true } -pin-project = { version = "1.1", optional = true } -pin-project-lite = { version = "0.2.16", optional = true } -http = "1.3.1" -http-body = "1.0.1" -tokio-util = "0.7.14" -anyhow = "1.0.98" -urlencoding = { version = "2.1.3", optional = true } +thiserror = "2" +hyper = { version = "1", features = ["full"] } +hyper-util = { version = "0.1", features = ["server-auto", "tokio"] } +tokio = { version = "1", optional = true } +bytes = "1" +http-body-util = "0.1" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["chrono"] } +async-trait = "0.1" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +uuid = "1.17" +url = "2" +serde_html_form = "0.2" +mime = "0.3" +futures-util = "0.3" +chrono = { version = "0.4", default-features = false, features = ["clock"] } +tokio-tungstenite = { version = "0.26", optional = true } +headers = "0.4" +tokio-stream = { version = "0.1", features = ["net"], optional = true } +pin-project = { version = "1", optional = true } +pin-project-lite = { version = "0.2", optional = true } +http = "1" +http-body = "1" +tokio-util = "0.7" +anyhow = "1" +urlencoding = { version = "2", optional = true } # Scheduler -cron = { version = "0.15.0", optional = true } +cron = { version = "0.15", optional = true } # Multipart -multer = { version = "3.1.0", optional = true } -multimap = { version = "0.10.0", features = ["serde"], optional = true } -tempfile = { version = "3.19.1", optional = true } -textnonce = { version = "1.0.0", optional = true } +multer = { version = "3", optional = true } +multimap = { version = "0.10", features = ["serde"], optional = true } +tempfile = { version = "3", optional = true } +textnonce = { version = "1", optional = true } # Template -tera = { version = "1.20.0", optional = true } +tera = { version = "1", optional = true } # Session -async-session = { version = "3.0.0", optional = true } -cookie = { version = "0.18.1", features = ["secure", "percent-encode"], optional = true } +async-session = { version = "3", optional = true } +cookie = { version = "0.18", features = ["secure", "percent-encode"], optional = true } # Grpc -tonic = { version = "0.13.0", optional = true } +tonic = { version = "0.13", optional = true } # Security -argon2 = { version = "0.5.3", optional = true } +argon2 = { version = "0.5", optional = true } pbkdf2 = { version = "0.12", features = ["simple"], optional = true } -aes-gcm = { version = "0.10.3", optional = true } +aes-gcm = { version = "0.10", optional = true } aes = { version = "0.8", optional = true } -rsa = { version = "0.9.8", optional = true } -mime_guess = "2.0.5" +rsa = { version = "0.9", optional = true } +mime_guess = "2" # tls tokio-rustls = { version = "0.26", optional = true, default-features = false, features = ["logging", "tls12"] } diff --git a/silent/src/core/adapt.rs b/silent/src/core/adapt.rs index ea2d623..125e23b 100644 --- a/silent/src/core/adapt.rs +++ b/silent/src/core/adapt.rs @@ -22,6 +22,7 @@ pub trait ResponseAdapt { fn tran_from_response(res: Response) -> Self; } +#[allow(clippy::result_large_err)] #[cfg(feature = "cookie")] fn get_cookie(req: &HyperRequest) -> Result { let mut jar = CookieJar::new(); diff --git a/silent/src/core/req_body.rs b/silent/src/core/req_body.rs index 2e85b2e..4ebe129 100644 --- a/silent/src/core/req_body.rs +++ b/silent/src/core/req_body.rs @@ -1,4 +1,4 @@ -use std::io::{Error as IoError, ErrorKind}; +use std::io::Error as IoError; use std::pin::Pin; use std::task::{Context, Poll}; @@ -41,9 +41,7 @@ impl Body for ReqBody { match &mut *self { ReqBody::Empty => Poll::Ready(None), ReqBody::Once(bytes) => Poll::Ready(Some(Ok(Frame::data(bytes.clone())))), - ReqBody::Incoming(body) => Pin::new(body) - .poll_frame(cx) - .map_err(|e| IoError::new(ErrorKind::Other, e)), + ReqBody::Incoming(body) => Pin::new(body).poll_frame(cx).map_err(IoError::other), } } @@ -70,7 +68,7 @@ impl Stream for ReqBody { fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match Body::poll_frame(self, cx) { Poll::Ready(Some(Ok(frame))) => Poll::Ready(frame.into_data().map(Ok).ok()), - Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(IoError::new(ErrorKind::Other, e)))), + Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(IoError::other(e)))), Poll::Ready(None) => Poll::Ready(None), Poll::Pending => Poll::Pending, } diff --git a/silent/src/error/mod.rs b/silent/src/error/mod.rs index f0fc072..89c4f6f 100644 --- a/silent/src/error/mod.rs +++ b/silent/src/error/mod.rs @@ -15,10 +15,6 @@ pub enum SilentError { /// IO 错误 #[error("io error")] IOError(#[from] io::Error), - #[cfg(feature = "upgrade")] - /// Websocket IO 错误 - #[error("io error")] - TungsteniteError(#[from] tokio_tungstenite::tungstenite::Error), /// 反序列化 错误 #[error("serde_json error `{0}`")] SerdeJsonError(#[from] serde_json::Error), diff --git a/silent/src/scheduler/process_time.rs b/silent/src/scheduler/process_time.rs index ab86ce0..8f61075 100644 --- a/silent/src/scheduler/process_time.rs +++ b/silent/src/scheduler/process_time.rs @@ -6,7 +6,7 @@ use std::str::FromStr; #[derive(Debug, Clone)] pub enum ProcessTime { Datetime(DateTime), - Crontab(Schedule), + Crontab(Box), } impl Serialize for ProcessTime { @@ -27,7 +27,7 @@ impl TryFrom for ProcessTime { fn try_from(value: String) -> Result { match DateTime::::from_str(&value) { Ok(datetime) => Ok(ProcessTime::Datetime(datetime)), - Err(_) => Ok(ProcessTime::Crontab(Schedule::from_str(&value)?)), + Err(_) => Ok(ProcessTime::Crontab(Box::from(Schedule::from_str(&value)?))), } } } @@ -38,7 +38,7 @@ impl TryFrom<&str> for ProcessTime { fn try_from(value: &str) -> Result { match DateTime::::from_str(value) { Ok(datetime) => Ok(ProcessTime::Datetime(datetime)), - Err(_) => Ok(ProcessTime::Crontab(Schedule::from_str(value)?)), + Err(_) => Ok(ProcessTime::Crontab(Box::from(Schedule::from_str(value)?))), } } } @@ -82,9 +82,11 @@ mod tests { assert!(!process_time.is_active()); let process_time = ProcessTime::try_from(datetime).unwrap(); assert!(process_time.is_active()); - let process_time = ProcessTime::Crontab(Schedule::from_str("* * * * * *").unwrap()); + let process_time = + ProcessTime::Crontab(Box::from(Schedule::from_str("* * * * * *").unwrap())); assert!(process_time.is_active()); - let process_time = ProcessTime::Crontab(Schedule::from_str("0 0 0 1 1 ? 2015").unwrap()); + let process_time = + ProcessTime::Crontab(Box::from(Schedule::from_str("0 0 0 1 1 ? 2015").unwrap())); assert!(!process_time.is_active()); assert!(ProcessTime::try_from("2023-01-01T00:00:00Z".to_string()).is_ok()); assert!(ProcessTime::try_from("2023-01-01 00:00:00").is_err()); diff --git a/silent/src/ws/websocket.rs b/silent/src/ws/websocket.rs index 3541d96..0b4321d 100644 --- a/silent/src/ws/websocket.rs +++ b/silent/src/ws/websocket.rs @@ -3,6 +3,7 @@ use crate::ws::message::Message; use crate::ws::upgrade::{Upgraded, WebSocketParts}; use crate::ws::websocket_handler::WebSocketHandler; use crate::{Result, SilentError}; +use anyhow::anyhow; use async_trait::async_trait; use futures_util::sink::{Sink, SinkExt}; use futures_util::stream::{Stream, StreamExt}; @@ -56,7 +57,10 @@ impl WebSocket { /// Send a message. #[allow(dead_code)] pub async fn send(&mut self, msg: Message) -> Result<()> { - self.upgrade.send(msg.inner).await.map_err(|e| e.into()) + self.upgrade + .send(msg.inner) + .await + .map_err(|e| anyhow!("send error: {}", e).into()) } /// Gracefully close this websocket. @@ -74,28 +78,28 @@ impl Sink for WebSocket { fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { Pin::new(&mut self.upgrade) .poll_ready(cx) - .map_err(|e| e.into()) + .map_err(|e| anyhow!("poll_ready error: {}", e).into()) } #[inline] fn start_send(mut self: Pin<&mut Self>, item: Message) -> Result<()> { Pin::new(&mut self.upgrade) .start_send(item.inner) - .map_err(|e| e.into()) + .map_err(|e| anyhow!("start_send error: {}", e).into()) } #[inline] fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { Pin::new(&mut self.upgrade) .poll_flush(cx) - .map_err(|e| e.into()) + .map_err(|e| anyhow!("poll_flush error: {}", e).into()) } #[inline] fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { Pin::new(&mut self.upgrade) .poll_close(cx) - .map_err(|e| e.into()) + .map_err(|e| anyhow!("poll_close error: {}", e).into()) } } @@ -200,7 +204,7 @@ where let (tx, mut rx) = unbounded_channel(); debug!("on_connect: {:?}", parts); if let Some(on_connect) = on_connect { - on_connect(parts.clone(), tx.clone()).await.unwrap(); + on_connect(parts.clone(), tx.clone()).await?; } let sender_parts = parts.clone(); let receiver_parts = parts; @@ -253,7 +257,7 @@ impl Stream for WebSocket { Some(Ok(item)) => Poll::Ready(Some(Ok(Message { inner: item }))), Some(Err(e)) => { debug!("websocket poll error: {}", e); - Poll::Ready(Some(Err(e.into()))) + Poll::Ready(Some(Err(anyhow!("websocket poll error: {}", e).into()))) } None => { debug!("websocket closed");