Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hyper-rustls #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
30 changes: 25 additions & 5 deletions src/http_client/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -45,6 +47,24 @@ impl HyperClient {
client: Arc::new(client),
}
}

#[cfg(feature = "hyper-tls")]
fn build_https_connector() -> HttpsConnector<RuntimeTcpConnector> {
// 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<RuntimeTcpConnector> {
// 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 {
Expand Down