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

Fail with TlsFeatureNotEnabled if connecting to wss without the feature #186

Merged
merged 3 commits into from Aug 20, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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