diff --git a/Cargo.toml b/Cargo.toml index fda2c1ac..0becc422 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ tokio = { version = "1.0", features = ["fs", "sync", "time"] } tokio-util = { version = "0.7.1", features = ["io"] } tracing = { version = "0.1.21", default-features = false, features = ["log", "std"] } tower-service = "0.3" -tokio-tungstenite = { version = "0.21", optional = true } +tokio-tungstenite = { version = "0.26.1", optional = true } percent-encoding = "2.1" pin-project = "1.0" tokio-rustls = { version = "0.26", default-features = false, features = ["logging", "tls12", "ring"], optional = true } diff --git a/src/filters/ws.rs b/src/filters/ws.rs index 9ca374fb..0e6498de 100644 --- a/src/filters/ws.rs +++ b/src/filters/ws.rs @@ -1,6 +1,5 @@ //! Websockets Filters -use std::borrow::Cow; use std::fmt; use std::future::Future; use std::pin::Pin; @@ -14,6 +13,7 @@ use futures_util::{future, ready, FutureExt, Sink, Stream, TryFutureExt}; use headers::{Connection, HeaderMapExt, SecWebsocketAccept, SecWebsocketKey, Upgrade}; use hyper::upgrade::OnUpgrade; use tokio_tungstenite::{ + tungstenite::Bytes, tungstenite::Utf8Bytes, tungstenite::protocol::{self, WebSocketConfig}, WebSocketStream, }; @@ -284,23 +284,23 @@ pub struct Message { impl Message { /// Construct a new Text `Message`. - pub fn text>(s: S) -> Message { + pub fn text>(bytes: B) -> Message { Message { - inner: protocol::Message::text(s), + inner: protocol::Message::text(bytes.into()), } } /// Construct a new Binary `Message`. - pub fn binary>>(v: V) -> Message { + pub fn binary>(bytes: B) -> Message { Message { - inner: protocol::Message::binary(v), + inner: protocol::Message::binary(bytes), } } /// Construct a new Ping `Message`. - pub fn ping>>(v: V) -> Message { + pub fn ping>(bytes: B) -> Message { Message { - inner: protocol::Message::Ping(v.into()), + inner: protocol::Message::Ping(bytes.into()), } } @@ -309,9 +309,9 @@ impl Message { /// Note that one rarely needs to manually construct a Pong message because the underlying tungstenite socket /// automatically responds to the Ping messages it receives. Manual construction might still be useful in some cases /// like in tests or to send unidirectional heartbeats. - pub fn pong>>(v: V) -> Message { + pub fn pong>(bytes: B) -> Message { Message { - inner: protocol::Message::Pong(v.into()), + inner: protocol::Message::Pong(bytes.into()), } } @@ -323,7 +323,7 @@ impl Message { } /// Construct a Close `Message` with a code and reason. - 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()), @@ -387,7 +387,7 @@ impl Message { } /// Destructure this message into binary data. - pub fn into_bytes(self) -> Vec { + pub fn into_bytes(self) -> Bytes { self.inner.into_data() } } @@ -398,7 +398,7 @@ impl fmt::Debug for Message { } } -impl From for Vec { +impl From for Bytes { fn from(m: Message) -> Self { m.into_bytes() } diff --git a/src/test.rs b/src/test.rs index 947c0902..ed30b632 100644 --- a/src/test.rs +++ b/src/test.rs @@ -572,7 +572,7 @@ impl WsBuilder { impl WsClient { /// Send a "text" websocket message to the server. pub async fn send_text(&mut self, text: impl Into) { - self.send(crate::ws::Message::text(text)).await; + self.send(crate::ws::Message::text(text.into())).await; } /// Send a websocket message to the server.