|
|
@ -42,7 +42,7 @@ |
|
|
|
unused_import_braces |
|
|
|
unused_import_braces |
|
|
|
)] |
|
|
|
)] |
|
|
|
|
|
|
|
|
|
|
|
pub use tungstenite; |
|
|
|
pub use ng_tungstenite as tungstenite; |
|
|
|
|
|
|
|
|
|
|
|
mod compat; |
|
|
|
mod compat; |
|
|
|
mod handshake; |
|
|
|
mod handshake; |
|
|
@ -71,7 +71,7 @@ use std::pin::Pin; |
|
|
|
use std::task::{Context, Poll}; |
|
|
|
use std::task::{Context, Poll}; |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
use tungstenite::{ |
|
|
|
use ng_tungstenite::{ |
|
|
|
client::IntoClientRequest, |
|
|
|
client::IntoClientRequest, |
|
|
|
handshake::{ |
|
|
|
handshake::{ |
|
|
|
client::{ClientHandshake, Response}, |
|
|
|
client::{ClientHandshake, Response}, |
|
|
@ -79,7 +79,7 @@ use tungstenite::{ |
|
|
|
HandshakeError, |
|
|
|
HandshakeError, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
use tungstenite::{ |
|
|
|
use ng_tungstenite::{ |
|
|
|
error::Error as WsError, |
|
|
|
error::Error as WsError, |
|
|
|
protocol::{Message, Role, WebSocket, WebSocketConfig}, |
|
|
|
protocol::{Message, Role, WebSocket, WebSocketConfig}, |
|
|
|
}; |
|
|
|
}; |
|
|
@ -93,7 +93,7 @@ pub mod gio; |
|
|
|
#[cfg(feature = "tokio-runtime")] |
|
|
|
#[cfg(feature = "tokio-runtime")] |
|
|
|
pub mod tokio; |
|
|
|
pub mod tokio; |
|
|
|
|
|
|
|
|
|
|
|
use tungstenite::protocol::CloseFrame; |
|
|
|
use ng_tungstenite::protocol::CloseFrame; |
|
|
|
|
|
|
|
|
|
|
|
/// Creates a WebSocket handshake from a request and a stream.
|
|
|
|
/// Creates a WebSocket handshake from a request and a stream.
|
|
|
|
/// For convenience, the user may call this with a url string, a URL,
|
|
|
|
/// For convenience, the user may call this with a url string, a URL,
|
|
|
@ -204,7 +204,7 @@ where |
|
|
|
C: Callback + Unpin, |
|
|
|
C: Callback + Unpin, |
|
|
|
{ |
|
|
|
{ |
|
|
|
let f = handshake::server_handshake(stream, move |allow_std| { |
|
|
|
let f = handshake::server_handshake(stream, move |allow_std| { |
|
|
|
tungstenite::accept_hdr_with_config(allow_std, callback, config) |
|
|
|
ng_tungstenite::accept_hdr_with_config(allow_std, callback, config) |
|
|
|
}); |
|
|
|
}); |
|
|
|
f.await.map_err(|e| match e { |
|
|
|
f.await.map_err(|e| match e { |
|
|
|
HandshakeError::Failure(e) => e, |
|
|
|
HandshakeError::Failure(e) => e, |
|
|
@ -436,8 +436,8 @@ where |
|
|
|
/// Get a domain from an URL.
|
|
|
|
/// Get a domain from an URL.
|
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
pub(crate) fn domain( |
|
|
|
pub(crate) fn domain( |
|
|
|
request: &tungstenite::handshake::client::Request, |
|
|
|
request: &ng_tungstenite::handshake::client::Request, |
|
|
|
) -> Result<String, tungstenite::Error> { |
|
|
|
) -> Result<String, ng_tungstenite::Error> { |
|
|
|
request |
|
|
|
request |
|
|
|
.uri() |
|
|
|
.uri() |
|
|
|
.host() |
|
|
|
.host() |
|
|
@ -455,8 +455,8 @@ pub(crate) fn domain( |
|
|
|
|
|
|
|
|
|
|
|
host.to_owned() |
|
|
|
host.to_owned() |
|
|
|
}) |
|
|
|
}) |
|
|
|
.ok_or(tungstenite::Error::Url( |
|
|
|
.ok_or(ng_tungstenite::Error::Url( |
|
|
|
tungstenite::error::UrlError::NoHostName, |
|
|
|
ng_tungstenite::error::UrlError::NoHostName, |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -468,8 +468,8 @@ pub(crate) fn domain( |
|
|
|
/// Get the port from an URL.
|
|
|
|
/// Get the port from an URL.
|
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
pub(crate) fn port( |
|
|
|
pub(crate) fn port( |
|
|
|
request: &tungstenite::handshake::client::Request, |
|
|
|
request: &ng_tungstenite::handshake::client::Request, |
|
|
|
) -> Result<u16, tungstenite::Error> { |
|
|
|
) -> Result<u16, ng_tungstenite::Error> { |
|
|
|
request |
|
|
|
request |
|
|
|
.uri() |
|
|
|
.uri() |
|
|
|
.port_u16() |
|
|
|
.port_u16() |
|
|
@ -478,8 +478,8 @@ pub(crate) fn port( |
|
|
|
Some("ws") => Some(80), |
|
|
|
Some("ws") => Some(80), |
|
|
|
_ => None, |
|
|
|
_ => None, |
|
|
|
}) |
|
|
|
}) |
|
|
|
.ok_or(tungstenite::Error::Url( |
|
|
|
.ok_or(ng_tungstenite::Error::Url( |
|
|
|
tungstenite::error::UrlError::UnsupportedUrlScheme, |
|
|
|
ng_tungstenite::error::UrlError::UnsupportedUrlScheme, |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -493,7 +493,7 @@ mod tests { |
|
|
|
))] |
|
|
|
))] |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn domain_strips_ipv6_brackets() { |
|
|
|
fn domain_strips_ipv6_brackets() { |
|
|
|
use tungstenite::client::IntoClientRequest; |
|
|
|
use ng_tungstenite::client::IntoClientRequest; |
|
|
|
|
|
|
|
|
|
|
|
let request = "ws://[::1]:80".into_client_request().unwrap(); |
|
|
|
let request = "ws://[::1]:80".into_client_request().unwrap(); |
|
|
|
assert_eq!(crate::domain(&request).unwrap(), "::1"); |
|
|
|
assert_eq!(crate::domain(&request).unwrap(), "::1"); |
|
|
@ -502,7 +502,7 @@ mod tests { |
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
#[cfg(feature = "handshake")] |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn requests_cannot_contain_invalid_uris() { |
|
|
|
fn requests_cannot_contain_invalid_uris() { |
|
|
|
use tungstenite::client::IntoClientRequest; |
|
|
|
use ng_tungstenite::client::IntoClientRequest; |
|
|
|
|
|
|
|
|
|
|
|
assert!("ws://[".into_client_request().is_err()); |
|
|
|
assert!("ws://[".into_client_request().is_err()); |
|
|
|
assert!("ws://[blabla/bla".into_client_request().is_err()); |
|
|
|
assert!("ws://[blabla/bla".into_client_request().is_err()); |
|
|
|