diff --git a/Cargo.toml b/Cargo.toml index 4eede35..a8a6c64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,20 +16,20 @@ rust-version = "1.64" [features] default = ["handshake"] -handshake = ["tungstenite/handshake"] +handshake = ["ng-tungstenite/handshake"] async-std-runtime = ["async-std", "handshake"] tokio-runtime = ["tokio", "handshake"] gio-runtime = ["gio", "glib", "handshake"] async-tls = ["real-async-tls", "handshake"] -async-native-tls = ["async-std-runtime", "real-async-native-tls", "tungstenite/native-tls"] -tokio-native-tls = ["tokio-runtime", "real-tokio-native-tls", "real-native-tls", "tungstenite/native-tls"] +async-native-tls = ["async-std-runtime", "real-async-native-tls", "ng-tungstenite/native-tls"] +tokio-native-tls = ["tokio-runtime", "real-tokio-native-tls", "real-native-tls", "ng-tungstenite/native-tls"] tokio-rustls-manual-roots = ["__rustls-tls"] tokio-rustls-webpki-roots = ["__rustls-tls", "webpki-roots"] tokio-rustls-native-certs = ["__rustls-tls", "rustls-native-certs"] tokio-openssl = ["tokio-runtime", "real-tokio-openssl", "openssl"] verbose-logging = [] -__rustls-tls = ["tokio-runtime", "real-tokio-rustls", "tungstenite/__rustls-tls"] +__rustls-tls = ["tokio-runtime", "real-tokio-rustls", "ng-tungstenite/__rustls-tls"] [package.metadata.docs.rs] features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "async-native-tls", "tokio-native-tls"] diff --git a/examples/server-custom-accept.rs b/examples/server-custom-accept.rs index bf2f97f..95ed960 100644 --- a/examples/server-custom-accept.rs +++ b/examples/server-custom-accept.rs @@ -40,7 +40,7 @@ use futures_channel::mpsc::{unbounded, UnboundedSender}; use futures_util::{future, pin_mut, stream::TryStreamExt, StreamExt}; use async_tungstenite::{tokio::TokioAdapter, WebSocketStream}; -use tungstenite::{ +use ng_tungstenite::{ handshake::derive_accept_key, protocol::{Message, Role}, }; diff --git a/src/async_std.rs b/src/async_std.rs index 51cf55a..fbd40dd 100644 --- a/src/async_std.rs +++ b/src/async_std.rs @@ -1,8 +1,8 @@ //! `async-std` integration. -use tungstenite::client::IntoClientRequest; -use tungstenite::handshake::client::{Request, Response}; -use tungstenite::protocol::WebSocketConfig; -use tungstenite::Error; +use ng_tungstenite::client::IntoClientRequest; +use ng_tungstenite::handshake::client::{Request, Response}; +use ng_tungstenite::protocol::WebSocketConfig; +use ng_tungstenite::Error; use async_std::net::TcpStream; @@ -17,10 +17,10 @@ pub(crate) mod async_native_tls { use async_native_tls::TlsStream; use real_async_native_tls as async_native_tls; - use tungstenite::client::uri_mode; - use tungstenite::handshake::client::Request; - use tungstenite::stream::Mode; - use tungstenite::Error; + use ng_tungstenite::client::uri_mode; + use ng_tungstenite::handshake::client::Request; + use ng_tungstenite::stream::Mode; + use ng_tungstenite::Error; use futures_io::{AsyncRead, AsyncWrite}; @@ -95,10 +95,10 @@ pub(crate) mod async_native_tls { pub(crate) mod dummy_tls { use futures_io::{AsyncRead, AsyncWrite}; - use tungstenite::client::{uri_mode, IntoClientRequest}; - use tungstenite::handshake::client::Request; - use tungstenite::stream::Mode; - use tungstenite::Error; + use ng_tungstenite::client::{uri_mode, IntoClientRequest}; + use ng_tungstenite::handshake::client::Request; + use ng_tungstenite::stream::Mode; + use ng_tungstenite::Error; use crate::{client_async_with_config, domain, Response, WebSocketConfig, WebSocketStream}; @@ -117,7 +117,7 @@ pub(crate) mod dummy_tls { match mode { Mode::Plain => Ok(socket), Mode::Tls => Err(Error::Url( - tungstenite::error::UrlError::TlsFeatureNotEnabled, + ng_tungstenite::error::UrlError::TlsFeatureNotEnabled, )), } } diff --git a/src/async_tls.rs b/src/async_tls.rs index 00bcc5d..92632c0 100644 --- a/src/async_tls.rs +++ b/src/async_tls.rs @@ -1,8 +1,8 @@ //! `async-tls` integration. -use tungstenite::client::{uri_mode, IntoClientRequest}; -use tungstenite::handshake::client::{Request, Response}; -use tungstenite::protocol::WebSocketConfig; -use tungstenite::Error; +use ng_tungstenite::client::{uri_mode, IntoClientRequest}; +use ng_tungstenite::handshake::client::{Request, Response}; +use ng_tungstenite::protocol::WebSocketConfig; +use ng_tungstenite::Error; use futures_io::{AsyncRead, AsyncWrite}; @@ -12,7 +12,7 @@ use async_tls::client::TlsStream; use async_tls::TlsConnector as AsyncTlsConnector; use real_async_tls as async_tls; -use tungstenite::stream::Mode; +use ng_tungstenite::stream::Mode; use crate::domain; use crate::stream::Stream as StreamSwitcher; diff --git a/src/compat.rs b/src/compat.rs index ffc1353..5ed1906 100644 --- a/src/compat.rs +++ b/src/compat.rs @@ -6,8 +6,8 @@ use std::task::{Context, Poll}; use futures_io::{AsyncRead, AsyncWrite}; use futures_util::task; +use ng_tungstenite::Error as WsError; use std::sync::Arc; -use tungstenite::Error as WsError; pub(crate) enum ContextWaker { Read, diff --git a/src/gio.rs b/src/gio.rs index ec66c0e..b7a65e5 100644 --- a/src/gio.rs +++ b/src/gio.rs @@ -1,5 +1,5 @@ //! `gio` integration. -use tungstenite::Error; +use ng_tungstenite::Error; use std::io; @@ -7,10 +7,10 @@ use gio::prelude::*; use futures_io::{AsyncRead, AsyncWrite}; -use tungstenite::client::{uri_mode, IntoClientRequest}; -use tungstenite::handshake::client::Request; -use tungstenite::handshake::server::{Callback, NoCallback}; -use tungstenite::stream::Mode; +use ng_tungstenite::client::{uri_mode, IntoClientRequest}; +use ng_tungstenite::handshake::client::Request; +use ng_tungstenite::handshake::server::{Callback, NoCallback}; +use ng_tungstenite::stream::Mode; use crate::{client_async_with_config, domain, port, Response, WebSocketConfig, WebSocketStream}; diff --git a/src/handshake.rs b/src/handshake.rs index c9c22ae..2e24afa 100644 --- a/src/handshake.rs +++ b/src/handshake.rs @@ -5,19 +5,19 @@ use crate::WebSocketStream; use futures_io::{AsyncRead, AsyncWrite}; #[allow(unused_imports)] use log::*; -use std::future::Future; -use std::io::{Read, Write}; -use std::pin::Pin; -use std::task::{Context, Poll}; -use tungstenite::WebSocket; +use ng_tungstenite::WebSocket; #[cfg(feature = "handshake")] -use tungstenite::{ +use ng_tungstenite::{ handshake::{ client::Response, server::Callback, HandshakeError as Error, HandshakeRole, MidHandshake as WsHandshake, }, ClientHandshake, ServerHandshake, }; +use std::future::Future; +use std::io::{Read, Write}; +use std::pin::Pin; +use std::task::{Context, Poll}; pub(crate) async fn without_handshake(stream: S, f: F) -> WebSocketStream where diff --git a/src/lib.rs b/src/lib.rs index 7e6bb9b..2901254 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ unused_import_braces )] -pub use tungstenite; +pub use ng_tungstenite as tungstenite; mod compat; mod handshake; @@ -71,7 +71,7 @@ use std::pin::Pin; use std::task::{Context, Poll}; #[cfg(feature = "handshake")] -use tungstenite::{ +use ng_tungstenite::{ client::IntoClientRequest, handshake::{ client::{ClientHandshake, Response}, @@ -79,7 +79,7 @@ use tungstenite::{ HandshakeError, }, }; -use tungstenite::{ +use ng_tungstenite::{ error::Error as WsError, protocol::{Message, Role, WebSocket, WebSocketConfig}, }; @@ -93,7 +93,7 @@ pub mod gio; #[cfg(feature = "tokio-runtime")] pub mod tokio; -use tungstenite::protocol::CloseFrame; +use ng_tungstenite::protocol::CloseFrame; /// Creates a WebSocket handshake from a request and a stream. /// For convenience, the user may call this with a url string, a URL, @@ -204,7 +204,7 @@ where C: Callback + Unpin, { 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 { HandshakeError::Failure(e) => e, @@ -436,8 +436,8 @@ where /// Get a domain from an URL. #[inline] pub(crate) fn domain( - request: &tungstenite::handshake::client::Request, -) -> Result { + request: &ng_tungstenite::handshake::client::Request, +) -> Result { request .uri() .host() @@ -455,8 +455,8 @@ pub(crate) fn domain( host.to_owned() }) - .ok_or(tungstenite::Error::Url( - tungstenite::error::UrlError::NoHostName, + .ok_or(ng_tungstenite::Error::Url( + ng_tungstenite::error::UrlError::NoHostName, )) } @@ -468,8 +468,8 @@ pub(crate) fn domain( /// Get the port from an URL. #[inline] pub(crate) fn port( - request: &tungstenite::handshake::client::Request, -) -> Result { + request: &ng_tungstenite::handshake::client::Request, +) -> Result { request .uri() .port_u16() @@ -478,8 +478,8 @@ pub(crate) fn port( Some("ws") => Some(80), _ => None, }) - .ok_or(tungstenite::Error::Url( - tungstenite::error::UrlError::UnsupportedUrlScheme, + .ok_or(ng_tungstenite::Error::Url( + ng_tungstenite::error::UrlError::UnsupportedUrlScheme, )) } @@ -493,7 +493,7 @@ mod tests { ))] #[test] fn domain_strips_ipv6_brackets() { - use tungstenite::client::IntoClientRequest; + use ng_tungstenite::client::IntoClientRequest; let request = "ws://[::1]:80".into_client_request().unwrap(); assert_eq!(crate::domain(&request).unwrap(), "::1"); @@ -502,7 +502,7 @@ mod tests { #[cfg(feature = "handshake")] #[test] fn requests_cannot_contain_invalid_uris() { - use tungstenite::client::IntoClientRequest; + use ng_tungstenite::client::IntoClientRequest; assert!("ws://[".into_client_request().is_err()); assert!("ws://[blabla/bla".into_client_request().is_err()); diff --git a/src/tokio.rs b/src/tokio.rs index 362bce3..7104144 100644 --- a/src/tokio.rs +++ b/src/tokio.rs @@ -1,9 +1,9 @@ //! `tokio` integration. -use tungstenite::client::IntoClientRequest; -use tungstenite::handshake::client::{Request, Response}; -use tungstenite::handshake::server::{Callback, NoCallback}; -use tungstenite::protocol::WebSocketConfig; -use tungstenite::Error; +use ng_tungstenite::client::IntoClientRequest; +use ng_tungstenite::handshake::client::{Request, Response}; +use ng_tungstenite::handshake::server::{Callback, NoCallback}; +use ng_tungstenite::protocol::WebSocketConfig; +use ng_tungstenite::Error; use tokio::net::TcpStream; diff --git a/src/tokio/async_tls.rs b/src/tokio/async_tls.rs index f2c156a..1bf51f8 100644 --- a/src/tokio/async_tls.rs +++ b/src/tokio/async_tls.rs @@ -1,8 +1,8 @@ use real_async_tls::client::TlsStream; use real_async_tls::TlsConnector; -use tungstenite::client::IntoClientRequest; -use tungstenite::Error; +use ng_tungstenite::client::IntoClientRequest; +use ng_tungstenite::Error; use crate::stream::Stream as StreamSwitcher; use crate::{Response, WebSocketConfig, WebSocketStream}; diff --git a/src/tokio/dummy_tls.rs b/src/tokio/dummy_tls.rs index 5706b22..8287aa2 100644 --- a/src/tokio/dummy_tls.rs +++ b/src/tokio/dummy_tls.rs @@ -1,7 +1,7 @@ -use tungstenite::client::{uri_mode, IntoClientRequest}; -use tungstenite::handshake::client::Request; -use tungstenite::stream::Mode; -use tungstenite::Error; +use ng_tungstenite::client::{uri_mode, IntoClientRequest}; +use ng_tungstenite::handshake::client::Request; +use ng_tungstenite::stream::Mode; +use ng_tungstenite::Error; use super::TokioAdapter; @@ -23,7 +23,7 @@ where match mode { Mode::Plain => Ok(TokioAdapter::new(socket)), Mode::Tls => Err(Error::Url( - tungstenite::error::UrlError::TlsFeatureNotEnabled, + ng_tungstenite::error::UrlError::TlsFeatureNotEnabled, )), } } diff --git a/src/tokio/native_tls.rs b/src/tokio/native_tls.rs index 50a93e7..1ed207d 100644 --- a/src/tokio/native_tls.rs +++ b/src/tokio/native_tls.rs @@ -1,10 +1,10 @@ use real_tokio_native_tls::TlsConnector as AsyncTlsConnector; use real_tokio_native_tls::TlsStream; -use tungstenite::client::{uri_mode, IntoClientRequest}; -use tungstenite::handshake::client::Request; -use tungstenite::stream::Mode; -use tungstenite::Error; +use ng_tungstenite::client::{uri_mode, IntoClientRequest}; +use ng_tungstenite::handshake::client::Request; +use ng_tungstenite::stream::Mode; +use ng_tungstenite::Error; use crate::stream::Stream as StreamSwitcher; use crate::{client_async_with_config, domain, Response, WebSocketConfig, WebSocketStream}; diff --git a/src/tokio/openssl.rs b/src/tokio/openssl.rs index 3327d16..7df3bc9 100644 --- a/src/tokio/openssl.rs +++ b/src/tokio/openssl.rs @@ -1,10 +1,10 @@ use openssl::ssl::{ConnectConfiguration, SslConnector, SslMethod}; use real_tokio_openssl::SslStream as TlsStream; -use tungstenite::client::{uri_mode, IntoClientRequest}; -use tungstenite::handshake::client::Request; -use tungstenite::stream::Mode; -use tungstenite::Error; +use ng_tungstenite::client::{uri_mode, IntoClientRequest}; +use ng_tungstenite::handshake::client::Request; +use ng_tungstenite::stream::Mode; +use ng_tungstenite::Error; use crate::stream::Stream as StreamSwitcher; use crate::{client_async_with_config, domain, Response, WebSocketConfig, WebSocketStream}; diff --git a/src/tokio/rustls.rs b/src/tokio/rustls.rs index aeb8ffb..21fdaaa 100644 --- a/src/tokio/rustls.rs +++ b/src/tokio/rustls.rs @@ -1,11 +1,11 @@ use real_tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName}; use real_tokio_rustls::{client::TlsStream, TlsConnector}; -use tungstenite::client::{uri_mode, IntoClientRequest}; -use tungstenite::error::TlsError; -use tungstenite::handshake::client::Request; -use tungstenite::stream::Mode; -use tungstenite::Error; +use ng_tungstenite::client::{uri_mode, IntoClientRequest}; +use ng_tungstenite::error::TlsError; +use ng_tungstenite::handshake::client::Request; +use ng_tungstenite::stream::Mode; +use ng_tungstenite::Error; use std::convert::TryFrom; diff --git a/tests/communication.rs b/tests/communication.rs index a326f86..7215a81 100644 --- a/tests/communication.rs +++ b/tests/communication.rs @@ -5,7 +5,7 @@ use async_std::task; use async_tungstenite::{accept_async, client_async, WebSocketStream}; use futures::prelude::*; use log::*; -use tungstenite::Message; +use ng_tungstenite::Message; async fn run_connection( connection: WebSocketStream,