From 108bc1fab1c8322a26553afef9140e1fa851afb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 23 Mar 2021 14:50:45 +0200 Subject: [PATCH] Fix tokio-openssl connect API After creating the SslStream it first has to be connected before it can actually be used to initiate the WebSocket connection. While this technically is a breaking API changes because of wrapping the stream in a Pin> and having this as part of the public API, the old API simply didn't work so if anybody's code fails to compile now they would've had non-functioning code anyway. --- src/tokio/openssl.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/tokio/openssl.rs b/src/tokio/openssl.rs index f878f8f..3327d16 100644 --- a/src/tokio/openssl.rs +++ b/src/tokio/openssl.rs @@ -12,7 +12,8 @@ use crate::{client_async_with_config, domain, Response, WebSocketConfig, WebSock use super::TokioAdapter; /// A stream that might be protected with TLS. -pub type MaybeTlsStream = StreamSwitcher, TokioAdapter>>; +pub type MaybeTlsStream = + StreamSwitcher, TokioAdapter>>>>; pub type AutoStream = MaybeTlsStream; @@ -40,7 +41,7 @@ where let connector = if let Some(connector) = connector { connector } else { - SslConnector::builder(SslMethod::tls_client()) + SslConnector::builder(SslMethod::tls()) .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? .build() .configure() @@ -51,8 +52,18 @@ where .into_ssl(&domain) .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; - TlsStream::new(ssl, socket) - .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))? + let mut stream = Box::pin( + TlsStream::new(ssl, socket) + .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?, + ); + + stream + .as_mut() + .connect() + .await + .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; + + stream }; Ok(StreamSwitcher::Tls(TokioAdapter::new(stream))) }