From 994d8534776c5594c6b6b620d0e4983d7eee55e2 Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Wed, 18 Dec 2024 14:17:42 +0800 Subject: [PATCH] chore(deps): update tokio-tungstenite requirement from 0.25 to 0.26 (#1012) --- Cargo.toml | 2 +- crates/extra/src/websocket.rs | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a5650cbee..bb3bb87b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,7 +124,7 @@ tokio-native-tls = "0.3" tokio-rustls = {version = "0.26", default-features = false } tokio-openssl = "0.6" tokio-stream = { version = "0.1", default-features = false } -tokio-tungstenite = { version = "0.25", default-features = false } +tokio-tungstenite = { version = "0.26", default-features = false } tokio-util = "0.7" tower = { version = "0.5", default-features = false } tracing-subscriber = { version = "0.3" } diff --git a/crates/extra/src/websocket.rs b/crates/extra/src/websocket.rs index fcf4ead7b..15c21a2b3 100644 --- a/crates/extra/src/websocket.rs +++ b/crates/extra/src/websocket.rs @@ -77,7 +77,6 @@ //! "#; //!``` -use std::borrow::Cow; use std::fmt::{self, Debug, Formatter}; use std::future::Future; use std::pin::Pin; @@ -94,8 +93,10 @@ use salvo_core::http::headers::{ use salvo_core::http::{StatusCode, StatusError}; use salvo_core::rt::tokio::TokioIo; use salvo_core::{Error, Request, Response}; -use tokio_tungstenite::tungstenite::protocol::frame::{Payload, Utf8Payload}; +use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode; +use tokio_tungstenite::tungstenite::protocol::frame::{CloseFrame, Utf8Bytes}; use tokio_tungstenite::tungstenite::protocol::{self, WebSocketConfig}; +use tokio_tungstenite::tungstenite::Bytes; use tokio_tungstenite::WebSocketStream; /// Creates a WebSocket Handler. @@ -391,7 +392,7 @@ pub struct Message { impl Message { /// Construct a new Text `Message`. #[inline] - pub fn text>(s: S) -> Message { + pub fn text>(s: S) -> Message { Message { inner: protocol::Message::text(s), } @@ -399,7 +400,7 @@ impl Message { /// Construct a new Binary `Message`. #[inline] - pub fn binary>(v: V) -> Message { + pub fn binary>(v: V) -> Message { Message { inner: protocol::Message::binary(v), } @@ -407,7 +408,7 @@ impl Message { /// Construct a new Ping `Message`. #[inline] - pub fn ping>(v: V) -> Message { + pub fn ping>(v: V) -> Message { Message { inner: protocol::Message::Ping(v.into()), } @@ -415,7 +416,7 @@ impl Message { /// Construct a new Pong `Message`. #[inline] - pub fn pong>(v: V) -> Message { + pub fn pong>(v: V) -> Message { Message { inner: protocol::Message::Pong(v.into()), } @@ -431,10 +432,10 @@ impl Message { /// Construct a Close `Message` with a code and reason. #[inline] - pub fn close_with(code: impl Into, reason: impl Into>) -> Message { + pub fn close_with(code: impl Into, reason: impl Into) -> Message { Message { - inner: protocol::Message::Close(Some(protocol::frame::CloseFrame { - code: protocol::frame::coding::CloseCode::from(code.into()), + inner: protocol::Message::Close(Some(CloseFrame { + code: CloseCode::from(code.into()), reason: reason.into(), })), } @@ -493,10 +494,10 @@ impl Message { #[inline] pub fn as_bytes(&self) -> &[u8] { match &self.inner { - protocol::Message::Text(s) => s.as_slice(), - protocol::Message::Binary(v) => v.as_slice(), - protocol::Message::Ping(v) => v.as_slice(), - protocol::Message::Pong(v) => v.as_slice(), + protocol::Message::Text(s) => s.as_bytes(), + protocol::Message::Binary(v) => v.as_ref(), + protocol::Message::Ping(v) => v.as_ref(), + protocol::Message::Pong(v) => v.as_ref(), protocol::Message::Close(_) => &[], protocol::Message::Frame(v) => v.payload(), }