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<Box<_>> 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.
pull/91/head
Sebastian Dröge 4 years ago
parent d28799bc12
commit 108bc1fab1
  1. 17
      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<S> = StreamSwitcher<TokioAdapter<S>, TokioAdapter<TlsStream<S>>>;
pub type MaybeTlsStream<S> =
StreamSwitcher<TokioAdapter<S>, TokioAdapter<std::pin::Pin<Box<TlsStream<S>>>>>;
pub type AutoStream<S> = MaybeTlsStream<S>;
@ -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))?;
let mut stream = Box::pin(
TlsStream::new(ssl, socket)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?
.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)))
}

Loading…
Cancel
Save