Bring tokio's async-tls and rustls impls in line with the others

pull/63/head
Constantin Nickel 4 years ago committed by Sebastian Dröge
parent 7dcaebccf9
commit cf9ca1ffae
  1. 23
      src/tokio/async_tls.rs
  2. 8
      src/tokio/rustls.rs

@ -1,6 +1,19 @@
use super::{Error, IntoClientRequest, Response, TokioAdapter, WebSocketConfig, WebSocketStream};
use real_async_tls::client::TlsStream;
use real_async_tls::TlsConnector;
use tungstenite::client::IntoClientRequest;
use tungstenite::Error;
use crate::stream::Stream as StreamSwitcher;
use std::marker::Unpin;
use crate::{Response, WebSocketConfig, WebSocketStream};
use super::TokioAdapter;
pub type MaybeTlsStream<S> = StreamSwitcher<S, TlsStream<S>>;
pub type AutoStream<S> = MaybeTlsStream<TokioAdapter<S>>;
pub type Connector = TlsConnector;
/// Creates a WebSocket handshake from a request and a stream,
/// upgrading the stream to TLS if required and using the given
@ -24,9 +37,3 @@ where
)
.await
}
pub type Connector = real_async_tls::TlsConnector;
pub type MaybeTlsStream<S> = StreamSwitcher<S, real_async_tls::client::TlsStream<S>>;
pub type AutoStream<S> = MaybeTlsStream<TokioAdapter<S>>;

@ -1,6 +1,6 @@
use real_tokio_rustls::rustls::ClientConfig;
use real_tokio_rustls::webpki::DNSNameRef;
use real_tokio_rustls::{client::TlsStream, TlsConnector as AsyncTlsConnector};
use real_tokio_rustls::{client::TlsStream, TlsConnector};
use tungstenite::client::{uri_mode, IntoClientRequest};
use tungstenite::handshake::client::Request;
@ -17,7 +17,7 @@ pub type MaybeTlsStream<S> = StreamSwitcher<TokioAdapter<S>, TokioAdapter<TlsStr
pub type AutoStream<S> = MaybeTlsStream<S>;
pub type Connector = AsyncTlsConnector;
pub type Connector = TlsConnector;
async fn wrap_stream<S>(
socket: S,
@ -39,7 +39,7 @@ where
config
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
AsyncTlsConnector::from(std::sync::Arc::new(config))
TlsConnector::from(std::sync::Arc::new(config))
};
let domain = DNSNameRef::try_from_ascii_str(&domain)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
@ -59,7 +59,7 @@ where
pub async fn client_async_tls_with_connector_and_config<R, S>(
request: R,
stream: S,
connector: Option<AsyncTlsConnector>,
connector: Option<Connector>,
config: Option<WebSocketConfig>,
) -> Result<(WebSocketStream<AutoStream<S>>, Response), Error>
where

Loading…
Cancel
Save