Skip to content

Commit

Permalink
Fail with TlsFeatureNotEnabled if connecting to wss without the featu…
Browse files Browse the repository at this point in the history
…re (#186)

* Fail with TlsFeatureNotEnabled if connecting to wss without the feature
* Fix imports
* rustfmt
  • Loading branch information
Darksonn committed Aug 20, 2021
1 parent 171a452 commit cb24743
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
10 changes: 1 addition & 9 deletions src/connect.rs
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Expand Up @@ -18,7 +18,7 @@ mod connect;
mod handshake;
#[cfg(feature = "stream")]
mod stream;
#[cfg(any(feature = "native-tls", feature = "__rustls-tls"))]
#[cfg(any(feature = "native-tls", feature = "__rustls-tls", feature = "connect"))]
mod tls;

use std::io::{Read, Write};
Expand Down Expand Up @@ -46,8 +46,10 @@ use tungstenite::{
protocol::{Message, Role, WebSocket, WebSocketConfig},
};

#[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, Connector};
pub use tls::{client_async_tls, client_async_tls_with_config};

#[cfg(feature = "connect")]
pub use connect::{connect_async, connect_async_with_config};
Expand Down
5 changes: 3 additions & 2 deletions src/tls.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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<R, S>(
request: R,
stream: S,
Expand Down Expand Up @@ -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())?;
Expand Down

0 comments on commit cb24743

Please sign in to comment.