Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
silent = { path = "../silent" }

[dev-dependencies]
criterion = "0.5"
criterion = "0.6"

[[bench]]
name = "route_benchmark"
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion examples/grpc_streaming/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ tokio-stream.workspace = true
h2.workspace = true

[build-dependencies]
tonic-build = { version = "0.13.0" }
tonic-build = { version = "0.13" }
2 changes: 1 addition & 1 deletion examples/tls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
80 changes: 40 additions & 40 deletions silent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
1 change: 1 addition & 0 deletions silent/src/core/adapt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub trait ResponseAdapt {
fn tran_from_response(res: Response<Self::Body>) -> Self;
}

#[allow(clippy::result_large_err)]
#[cfg(feature = "cookie")]
fn get_cookie(req: &HyperRequest<ReqBody>) -> Result<CookieJar, SilentError> {
let mut jar = CookieJar::new();
Expand Down
8 changes: 3 additions & 5 deletions silent/src/core/req_body.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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),
}
}

Expand All @@ -70,7 +68,7 @@ impl Stream for ReqBody {
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
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,
}
Expand Down
4 changes: 0 additions & 4 deletions silent/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 7 additions & 5 deletions silent/src/scheduler/process_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::str::FromStr;
#[derive(Debug, Clone)]
pub enum ProcessTime {
Datetime(DateTime<Local>),
Crontab(Schedule),
Crontab(Box<Schedule>),
}

impl Serialize for ProcessTime {
Expand All @@ -27,7 +27,7 @@ impl TryFrom<String> for ProcessTime {
fn try_from(value: String) -> Result<Self, Self::Error> {
match DateTime::<Local>::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)?))),
}
}
}
Expand All @@ -38,7 +38,7 @@ impl TryFrom<&str> for ProcessTime {
fn try_from(value: &str) -> Result<Self, Self::Error> {
match DateTime::<Local>::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)?))),
}
}
}
Expand Down Expand Up @@ -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());
Expand Down
18 changes: 11 additions & 7 deletions silent/src/ws/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand All @@ -74,28 +78,28 @@ impl Sink<Message> for WebSocket {
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
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<Result<()>> {
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<Result<()>> {
Pin::new(&mut self.upgrade)
.poll_close(cx)
.map_err(|e| e.into())
.map_err(|e| anyhow!("poll_close error: {}", e).into())
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Loading