Skip to content

Commit

Permalink
Fail before connecting if TLS support is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
maugier committed Aug 12, 2024
1 parent c8b132b commit 914c521
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ pub fn connect_with_config<Req: IntoClientRequest>(
) -> Result<(WebSocket<MaybeTlsStream<TcpStream>>, Response)> {
let uri = request.uri();
let mode = uri_mode(uri)?;

#[cfg(not(any(feature = "native-tls", feature = "__rustls-tls")))]
if let Mode::Tls = mode {
return Err(Error::Url(UrlError::TlsFeatureNotEnabled));
}

let host = request.uri().host().ok_or(Error::Url(UrlError::NoHostName))?;
let host = if host.starts_with('[') { &host[1..host.len() - 1] } else { host };
let port = uri.port_u16().unwrap_or(match mode {
Expand All @@ -63,10 +69,7 @@ pub fn connect_with_config<Req: IntoClientRequest>(
NoDelay::set_nodelay(&mut stream, true)?;

#[cfg(not(any(feature = "native-tls", feature = "__rustls-tls")))]
let client = match mode {
Mode::Plain => client_with_config(request, MaybeTlsStream::Plain(stream), config),
Mode::Tls => return Err(Error::Url(UrlError::TlsFeatureNotEnabled)),
};
let client = client_with_config(request, MaybeTlsStream::Plain(stream), config);

#[cfg(any(feature = "native-tls", feature = "__rustls-tls"))]
let client = crate::tls::client_tls_with_config(request, stream, config, None);
Expand Down

0 comments on commit 914c521

Please sign in to comment.