mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
do not use Arc for rustls config
This commit is contained in:
parent
a5f80a25ff
commit
0da3fdcb09
@ -26,21 +26,51 @@ use native_tls::{Error as TlsError, TlsConnector, TlsStream};
|
|||||||
#[cfg(all(feature = "tls", not(feature = "alpn")))]
|
#[cfg(all(feature = "tls", not(feature = "alpn")))]
|
||||||
use tokio_tls::TlsConnectorExt;
|
use tokio_tls::TlsConnectorExt;
|
||||||
|
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
use rustls::ClientConfig;
|
use rustls::ClientConfig;
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
use std::io::Error as TLSError;
|
use std::io::Error as TLSError;
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
use tokio_rustls::ClientConfigExt;
|
use tokio_rustls::ClientConfigExt;
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
use webpki::DNSNameRef;
|
use webpki::DNSNameRef;
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
use webpki_roots;
|
use webpki_roots;
|
||||||
|
|
||||||
use server::IoStream;
|
use server::IoStream;
|
||||||
use {HAS_OPENSSL, HAS_TLS, HAS_RUSTLS};
|
use {HAS_OPENSSL, HAS_RUSTLS, HAS_TLS};
|
||||||
|
|
||||||
/// Client connector usage stats
|
/// Client connector usage stats
|
||||||
#[derive(Default, Message)]
|
#[derive(Default, Message)]
|
||||||
@ -153,7 +183,12 @@ pub enum ClientConnectorError {
|
|||||||
SslError(#[cause] TlsError),
|
SslError(#[cause] TlsError),
|
||||||
|
|
||||||
/// SSL error
|
/// SSL error
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
#[fail(display = "{}", _0)]
|
#[fail(display = "{}", _0)]
|
||||||
SslError(#[cause] TLSError),
|
SslError(#[cause] TLSError),
|
||||||
|
|
||||||
@ -211,7 +246,12 @@ pub struct ClientConnector {
|
|||||||
connector: SslConnector,
|
connector: SslConnector,
|
||||||
#[cfg(all(feature = "tls", not(feature = "alpn")))]
|
#[cfg(all(feature = "tls", not(feature = "alpn")))]
|
||||||
connector: TlsConnector,
|
connector: TlsConnector,
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
connector: Arc<ClientConfig>,
|
connector: Arc<ClientConfig>,
|
||||||
|
|
||||||
stats: ClientConnectorStats,
|
stats: ClientConnectorStats,
|
||||||
@ -282,13 +322,18 @@ impl Default for ClientConnector {
|
|||||||
paused: Paused::No,
|
paused: Paused::No,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
{
|
{
|
||||||
let mut config = ClientConfig::new();
|
let mut config = ClientConfig::new();
|
||||||
config
|
config
|
||||||
.root_store
|
.root_store
|
||||||
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
|
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
|
||||||
ClientConnector::with_connector(Arc::new(config))
|
ClientConnector::with_connector(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "alpn", feature = "tls", feature = "rust-tls")))]
|
#[cfg(not(any(feature = "alpn", feature = "tls", feature = "rust-tls")))]
|
||||||
@ -380,7 +425,12 @@ impl ClientConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
/// Create `ClientConnector` actor with custom `SslConnector` instance.
|
/// Create `ClientConnector` actor with custom `SslConnector` instance.
|
||||||
///
|
///
|
||||||
/// By default `ClientConnector` uses very a simple SSL configuration.
|
/// By default `ClientConnector` uses very a simple SSL configuration.
|
||||||
@ -425,11 +475,11 @@ impl ClientConnector {
|
|||||||
/// });
|
/// });
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn with_connector(connector: Arc<ClientConfig>) -> ClientConnector {
|
pub fn with_connector(connector: ClientConfig) -> ClientConnector {
|
||||||
let (tx, rx) = mpsc::unbounded();
|
let (tx, rx) = mpsc::unbounded();
|
||||||
|
|
||||||
ClientConnector {
|
ClientConnector {
|
||||||
connector,
|
connector: Arc::new(connector),
|
||||||
stats: ClientConnectorStats::default(),
|
stats: ClientConnectorStats::default(),
|
||||||
subscriber: None,
|
subscriber: None,
|
||||||
acq_tx: tx,
|
acq_tx: tx,
|
||||||
@ -806,7 +856,12 @@ impl ClientConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "rust-tls", not(any(feature = "alpn", feature = "tls"))))]
|
#[cfg(
|
||||||
|
all(
|
||||||
|
feature = "rust-tls",
|
||||||
|
not(any(feature = "alpn", feature = "tls"))
|
||||||
|
)
|
||||||
|
)]
|
||||||
match res {
|
match res {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let _ = waiter.tx.send(Err(err.into()));
|
let _ = waiter.tx.send(Err(err.into()));
|
||||||
@ -815,7 +870,8 @@ impl ClientConnector {
|
|||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
act.stats.opened += 1;
|
act.stats.opened += 1;
|
||||||
if conn.0.ssl {
|
if conn.0.ssl {
|
||||||
let host = DNSNameRef::try_from_ascii_str(&key.host).unwrap();
|
let host =
|
||||||
|
DNSNameRef::try_from_ascii_str(&key.host).unwrap();
|
||||||
fut::Either::A(
|
fut::Either::A(
|
||||||
act.connector
|
act.connector
|
||||||
.connect_async(host, stream)
|
.connect_async(host, stream)
|
||||||
|
@ -17,8 +17,6 @@ use tokio::runtime::current_thread::Runtime;
|
|||||||
use openssl::ssl::SslAcceptorBuilder;
|
use openssl::ssl::SslAcceptorBuilder;
|
||||||
#[cfg(all(feature = "rust-tls"))]
|
#[cfg(all(feature = "rust-tls"))]
|
||||||
use rustls::ServerConfig;
|
use rustls::ServerConfig;
|
||||||
//#[cfg(all(feature = "rust-tls"))]
|
|
||||||
//use std::sync::Arc;
|
|
||||||
|
|
||||||
use application::{App, HttpApplication};
|
use application::{App, HttpApplication};
|
||||||
use body::Binary;
|
use body::Binary;
|
||||||
@ -152,7 +150,7 @@ impl TestServer {
|
|||||||
let mut config = ClientConfig::new();
|
let mut config = ClientConfig::new();
|
||||||
let pem_file = &mut BufReader::new(File::open("tests/cert.pem").unwrap());
|
let pem_file = &mut BufReader::new(File::open("tests/cert.pem").unwrap());
|
||||||
config.root_store.add_pem_file(pem_file).unwrap();
|
config.root_store.add_pem_file(pem_file).unwrap();
|
||||||
ClientConnector::with_connector(Arc::new(config)).start()
|
ClientConnector::with_connector(config).start()
|
||||||
}
|
}
|
||||||
#[cfg(not(any(feature = "alpn", feature = "rust-tls")))]
|
#[cfg(not(any(feature = "alpn", feature = "rust-tls")))]
|
||||||
{
|
{
|
||||||
@ -209,8 +207,7 @@ impl TestServer {
|
|||||||
|
|
||||||
/// Connect to websocket server at a given path
|
/// Connect to websocket server at a given path
|
||||||
pub fn ws_at(
|
pub fn ws_at(
|
||||||
&mut self,
|
&mut self, path: &str,
|
||||||
path: &str,
|
|
||||||
) -> Result<(ws::ClientReader, ws::ClientWriter), ws::ClientError> {
|
) -> Result<(ws::ClientReader, ws::ClientWriter), ws::ClientError> {
|
||||||
let url = self.url(path);
|
let url = self.url(path);
|
||||||
self.rt
|
self.rt
|
||||||
|
Loading…
Reference in New Issue
Block a user