diff --git a/Cargo.toml b/Cargo.toml index f573c3f..4b651c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,9 @@ isahc = { version = "0.7", optional = true, default-features = false, features = # hyper-client hyper = { version = "0.12.32", optional = true, default-features = false } hyper-tls = { version = "0.3.2", optional = true } +hyper-rustls = { version = "0.17.0", optional = true } native-tls = { version = "0.2.2", optional = true } +rustls = { version = "0.16.0", optional = true } runtime = { version = "0.3.0-alpha.6", optional = true } runtime-raw = { version = "0.3.0-alpha.4", optional = true } runtime-tokio = { version = "0.3.0-alpha.5", optional = true } diff --git a/src/http_client/hyper.rs b/src/http_client/hyper.rs index 4c14598..70de532 100644 --- a/src/http_client/hyper.rs +++ b/src/http_client/hyper.rs @@ -6,7 +6,13 @@ use futures::future::FutureObj; use futures::prelude::*; use futures::task::SpawnError; use hyper::client::connect as hyper_connect; +#[cfg(feature = "hyper-tls")] use hyper_tls::HttpsConnector; +#[cfg(feature = "hyper-rustls")] +use hyper_rustls::HttpsConnector; +#[cfg(feature = "hyper-rustls")] +use rustls::ClientConfig; +#[cfg(feature = "hyper-tls")] use native_tls::TlsConnector; use runtime::net::TcpStream; use runtime_raw::Runtime; @@ -27,11 +33,7 @@ pub struct HyperClient { impl HyperClient { /// Create a new instance. pub(crate) fn new() -> Self { - // Create a TLS decoder, TCP stream, and combine them into a `Connector` to be passed to - // Hyper. - let tcp_connector = RuntimeTcpConnector::new(); - let tls_connector = TlsConnector::new().unwrap(); - let https = HttpsConnector::from((tcp_connector, tls_connector)); + let https = Self::build_https_connector(); // Create the Hyper client with the `Connector`, and make sure we use `runtime-tokio` to // spawn futures. Unfortunately, if futures are spawned onto `runtime-native`, we get weird @@ -45,6 +47,24 @@ impl HyperClient { client: Arc::new(client), } } + + #[cfg(feature = "hyper-tls")] + fn build_https_connector() -> HttpsConnector { + // Create a TLS decoder, TCP stream, and combine them into a `Connector` to be passed to + // Hyper. + let tcp_connector = RuntimeTcpConnector::new(); + let tls_connector = TlsConnector::new().unwrap(); + HttpsConnector::from((tcp_connector, tls_connector)) + } + + #[cfg(feature = "hyper-rustls")] + pub(crate) fn build_https_connector() -> HttpsConnector { + // Create a TLS configuration, TCP stream, and combine them into a `Connector` to be passed + // to Hyper. + let tcp_connector = RuntimeTcpConnector::new(); + let client_config = ClientConfig::new(); + HttpsConnector::from((tcp_connector, client_config)) + } } impl Clone for HyperClient {