Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump tokio-tungstenite to 0.24 #12

Merged
merged 2 commits into from
Dec 12, 2024
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ futures-util = { version = "0.3", default-features = false, features = [


[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio-tungstenite = "0.21"
tokio-tungstenite = "0.24"
tokio = { version = "1.36", default-features = false, features = ["net"] }
native-tls = { version = "0.2", default-features = false, optional = true }
rustls = { version = "0.22", default-features = false, optional = true }
rustls = { version = "0.23", default-features = false, optional = true }


[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
21 changes: 21 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,23 @@ pub enum CapacityError {
},
}

/// Indicates the specific type/cause of a subprotocol header error.
#[derive(Error, Clone, PartialEq, Eq, Debug, Copy)]
pub enum SubProtocolError {
/// The server sent a subprotocol to a client handshake request but none was requested
#[error("Server sent a subprotocol but none was requested")]
ServerSentSubProtocolNoneRequested,

/// The server sent an invalid subprotocol to a client handhshake request
#[error("Server sent an invalid subprotocol")]
InvalidSubProtocol,

/// The server sent no subprotocol to a client handshake request that requested one or more
/// subprotocols
#[error("Server sent no subprotocol")]
NoSubProtocol,
}

/// Indicates the specific type/cause of a protocol error.
#[derive(Error, Debug, PartialEq, Eq, Clone)]
pub enum ProtocolError {
Expand All @@ -169,6 +186,10 @@ pub enum ProtocolError {
/// The `Sec-WebSocket-Accept` header is either not present or does not specify the correct key value.
#[error("Key mismatch in \"Sec-WebSocket-Accept\" header")]
SecWebSocketAcceptKeyMismatch,
/// The `Sec-WebSocket-Protocol` header was invalid
#[error("SubProtocol error: {0}")]
#[allow(clippy::enum_variant_names)]
SecWebSocketSubProtocolError(SubProtocolError),
/// Garbage data encountered after client request.
#[error("Junk after client request")]
JunkAfterRequest,
Expand Down
6 changes: 4 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl Message {
}

/// Attempt to consume the WebSocket message and convert it to a String.
#[allow(clippy::result_large_err)]
pub fn into_text(self) -> Result<String, crate::Error> {
match self {
Message::Text(string) => Ok(string),
Expand All @@ -88,6 +89,7 @@ impl Message {

/// Attempt to get a &str from the WebSocket message,
/// this will try to convert binary data to utf8.
#[allow(clippy::result_large_err)]
pub fn to_text(&self) -> Result<&str, crate::Error> {
match *self {
Message::Text(ref string) => Ok(string),
Expand Down Expand Up @@ -155,7 +157,7 @@ pub struct CloseFrame<'t> {
pub reason: std::borrow::Cow<'t, str>,
}

impl<'t> CloseFrame<'t> {
impl CloseFrame<'_> {
/// Convert into a owned string.
pub fn into_owned(self) -> CloseFrame<'static> {
CloseFrame {
Expand All @@ -165,7 +167,7 @@ impl<'t> CloseFrame<'t> {
}
}

impl<'t> std::fmt::Display for CloseFrame<'t> {
impl std::fmt::Display for CloseFrame<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{} ({})", self.reason, self.code)
}
Expand Down
17 changes: 17 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ impl From<ProtocolError> for crate::error::ProtocolError {
ProtocolError::InvalidCloseSequence => {
crate::error::ProtocolError::InvalidCloseSequence
}
ProtocolError::SecWebSocketSubProtocolError(sub_protocol_error) => {
crate::error::ProtocolError::SecWebSocketSubProtocolError(sub_protocol_error.into())
}
}
}
}
Expand All @@ -258,6 +261,20 @@ impl From<TlsError> for crate::error::TlsError {
}
}

impl From<SubProtocolError> for crate::error::SubProtocolError {
fn from(error: SubProtocolError) -> Self {
match error {
SubProtocolError::ServerSentSubProtocolNoneRequested => {
crate::error::SubProtocolError::ServerSentSubProtocolNoneRequested
}
SubProtocolError::InvalidSubProtocol => {
crate::error::SubProtocolError::InvalidSubProtocol
}
SubProtocolError::NoSubProtocol => crate::error::SubProtocolError::NoSubProtocol,
}
}
}

impl From<Data> for crate::error::Data {
fn from(data: Data) -> Self {
match data {
Expand Down
Loading