From 7d3472210ecc7a8064e515ba3550abbdeafc7c32 Mon Sep 17 00:00:00 2001 From: Yiyu Lin Date: Tue, 17 Dec 2024 20:23:46 +0800 Subject: [PATCH] chore: bump `thiserror` and `tokio-tungstenite` (#931) * chore: bump `thiserror` and `tokio-tungstenite` * fix test --------- Co-authored-by: hzlinyiyu --- Cargo.toml | 2 +- examples/poem/custom-error/Cargo.toml | 2 +- poem/Cargo.toml | 4 ++-- poem/src/web/websocket/mod.rs | 12 ++++-------- poem/src/web/websocket/utils.rs | 18 +++++++++--------- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0b8aea4d6b..4419a92b4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ tokio = "1.39.1" serde_json = "1.0.68" sonic-rs = "0.3.5" serde = { version = "1.0.130", features = ["derive"] } -thiserror = "1.0.30" +thiserror = "2.0" regex = "1.5.5" mime = "0.3.16" tracing = "0.1.36" diff --git a/examples/poem/custom-error/Cargo.toml b/examples/poem/custom-error/Cargo.toml index 6ed5de8aeb..dfb1b71a2d 100644 --- a/examples/poem/custom-error/Cargo.toml +++ b/examples/poem/custom-error/Cargo.toml @@ -8,4 +8,4 @@ publish.workspace = true poem.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } tracing-subscriber.workspace = true -thiserror = "1.0.30" +thiserror = "2.0" diff --git a/poem/Cargo.toml b/poem/Cargo.toml index 7f50d492b8..83b5b9982a 100644 --- a/poem/Cargo.toml +++ b/poem/Cargo.toml @@ -99,7 +99,7 @@ sync_wrapper = { version = "1.0.0", features = ["futures"] } # Non-feature optional dependencies multer = { version = "3.0.0", features = ["tokio"], optional = true } -tokio-tungstenite = { version = "0.23.1", optional = true } +tokio-tungstenite = { version = "0.25", optional = true } tokio-rustls = { workspace = true, optional = true } rustls-pemfile = { version = "2.0.0", optional = true } async-compression = { version = "0.4.0", optional = true, features = [ @@ -132,7 +132,7 @@ libcookie = { package = "cookie", version = "0.18", features = [ ], optional = true } opentelemetry-http = { version = "0.27.0", optional = true } opentelemetry-semantic-conventions = { version = "0.27.0", optional = true, features = [ - "semconv_experimental" + "semconv_experimental", ] } opentelemetry-prometheus = { version = "0.17.0", optional = true } libprometheus = { package = "prometheus", version = "0.13.0", optional = true } diff --git a/poem/src/web/websocket/mod.rs b/poem/src/web/websocket/mod.rs index 914bb7b25f..c5941c56c7 100644 --- a/poem/src/web/websocket/mod.rs +++ b/poem/src/web/websocket/mod.rs @@ -137,25 +137,21 @@ mod tests { .unwrap(); client_stream - .send(tokio_tungstenite::tungstenite::Message::Text( - "aBc".to_string(), - )) + .send(tokio_tungstenite::tungstenite::Message::Text("aBc".into())) .await .unwrap(); assert_eq!( client_stream.next().await.unwrap().unwrap(), - tokio_tungstenite::tungstenite::Message::Text("ABC".to_string()) + tokio_tungstenite::tungstenite::Message::Text("ABC".into()) ); client_stream - .send(tokio_tungstenite::tungstenite::Message::Text( - "def".to_string(), - )) + .send(tokio_tungstenite::tungstenite::Message::Text("def".into())) .await .unwrap(); assert_eq!( client_stream.next().await.unwrap().unwrap(), - tokio_tungstenite::tungstenite::Message::Text("DEF".to_string()) + tokio_tungstenite::tungstenite::Message::Text("DEF".into()) ); handle.abort(); diff --git a/poem/src/web/websocket/utils.rs b/poem/src/web/websocket/utils.rs index c5e879b0cd..e0207bb028 100644 --- a/poem/src/web/websocket/utils.rs +++ b/poem/src/web/websocket/utils.rs @@ -41,10 +41,10 @@ impl From for Message { use tokio_tungstenite::tungstenite::Message::*; match msg { - Text(data) => Message::Text(data), - Binary(data) => Message::Binary(data), - Ping(data) => Message::Ping(data), - Pong(data) => Message::Pong(data), + Text(data) => Message::Text(data.to_string()), + Binary(data) => Message::Binary(data.as_slice().into()), + Ping(data) => Message::Ping(data.as_slice().into()), + Pong(data) => Message::Pong(data.as_slice().into()), Close(cf) => Message::Close(cf.map(|cf| (cf.code.into(), cf.reason.to_string()))), Frame(_) => unreachable!(), } @@ -54,13 +54,13 @@ impl From for Message { #[doc(hidden)] impl From for tokio_tungstenite::tungstenite::Message { fn from(msg: Message) -> Self { - use tokio_tungstenite::tungstenite::Message::*; + use tokio_tungstenite::tungstenite::{protocol::frame::Payload, Message::*}; match msg { - Message::Text(data) => Text(data), - Message::Binary(data) => Binary(data), - Message::Ping(data) => Ping(data), - Message::Pong(data) => Pong(data), + Message::Text(data) => Text(data.into()), + Message::Binary(data) => Binary(Payload::Vec(data)), + Message::Ping(data) => Ping(Payload::Vec(data)), + Message::Pong(data) => Pong(Payload::Vec(data)), Message::Close(cf) => Close(cf.map(|(code, reason)| CloseFrame { code: code.into(), reason: reason.into(),