From af536b122433cfe2fee9675505aec9da00b240d7 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 19 Aug 2021 07:31:21 +0000 Subject: [PATCH 1/3] Fail with TlsFeatureNotEnabled if connecting to wss without the feature --- src/connect.rs | 10 +--------- src/lib.rs | 4 ++-- src/tls.rs | 5 +++-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/connect.rs b/src/connect.rs index fa33434..ff6a8c3 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -48,15 +48,7 @@ where let try_socket = TcpStream::connect(addr).await; let socket = try_socket.map_err(Error::Io)?; - #[cfg(not(any(feature = "native-tls", feature = "__rustls-tls")))] - { - crate::client_async_with_config(request, MaybeTlsStream::Plain(socket), config).await - } - - #[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] - { - crate::tls::client_async_tls_with_config(request, socket, config, None).await - } + crate::tls::client_async_tls_with_config(request, socket, config, None).await } /// The same as `connect_async()` but the one can specify a websocket configuration, diff --git a/src/lib.rs b/src/lib.rs index bd79305..bdb9c32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,6 @@ mod connect; mod handshake; #[cfg(feature = "stream")] mod stream; -#[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] mod tls; use std::io::{Read, Write}; @@ -47,7 +46,8 @@ use tungstenite::{ }; #[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] -pub use tls::{client_async_tls, client_async_tls_with_config, Connector}; +pub use tls::{client_async_tls, client_async_tls_with_config}; +pub use tls::Connector; #[cfg(feature = "connect")] pub use connect::{connect_async, connect_async_with_config}; diff --git a/src/tls.rs b/src/tls.rs index 0efd581..50436d3 100644 --- a/src/tls.rs +++ b/src/tls.rs @@ -5,7 +5,7 @@ use tungstenite::{ client::uri_mode, error::Error, handshake::client::Response, protocol::WebSocketConfig, }; -use crate::{client_async_with_config, domain, IntoClientRequest, WebSocketStream}; +use crate::{client_async_with_config, IntoClientRequest, WebSocketStream}; pub use crate::stream::MaybeTlsStream; @@ -142,6 +142,7 @@ mod encryption { /// Creates a WebSocket handshake from a request and a stream, /// upgrading the stream to TLS if required. +#[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] pub async fn client_async_tls( request: R, stream: S, @@ -173,7 +174,7 @@ where let request = request.into_client_request()?; #[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] - let domain = domain(&request)?; + let domain = crate::domain(&request)?; // Make sure we check domain and mode first. URL must be valid. let mode = uri_mode(&request.uri())?; From e0eafc43fc7e40b0bfbdfb35b366ab6719b39f7d Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 19 Aug 2021 13:54:10 +0000 Subject: [PATCH 2/3] Fix imports --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bdb9c32..83ffa5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ mod connect; mod handshake; #[cfg(feature = "stream")] mod stream; +#[cfg(any(feature = "native-tls", feature = "__rustls-tls", feature = "connect"))] mod tls; use std::io::{Read, Write}; @@ -47,6 +48,7 @@ use tungstenite::{ #[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] pub use tls::{client_async_tls, client_async_tls_with_config}; +#[cfg(any(feature = "native-tls", feature = "__rustls-tls", feature = "connect"))] pub use tls::Connector; #[cfg(feature = "connect")] From 787ab83bca6d28e4248b96a700b744c64977445d Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Thu, 19 Aug 2021 14:37:45 +0000 Subject: [PATCH 3/3] rustfmt --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 83ffa5f..2110383 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,10 +46,10 @@ use tungstenite::{ protocol::{Message, Role, WebSocket, WebSocketConfig}, }; -#[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] -pub use tls::{client_async_tls, client_async_tls_with_config}; #[cfg(any(feature = "native-tls", feature = "__rustls-tls", feature = "connect"))] pub use tls::Connector; +#[cfg(any(feature = "native-tls", feature = "__rustls-tls"))] +pub use tls::{client_async_tls, client_async_tls_with_config}; #[cfg(feature = "connect")] pub use connect::{connect_async, connect_async_with_config};