diff --git a/Cargo.toml b/Cargo.toml index 89dc44f..ef1ed48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ categories = ["web-programming::http-client"] bytes = "0.4" futures = "0.1.14" hyper = "0.11" -hyper-tls = "0.1.1" +hyper-tls = "0.1.2" libflate = "0.1.5" log = "0.3" native-tls = "0.1" diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 5409c65..260d7e8 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -22,58 +22,13 @@ use {Certificate, IntoUrl, Method, proxy, Proxy, StatusCode, Url}; static DEFAULT_USER_AGENT: &'static str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); -/// A `Client` to make Requests with. -/// -/// The Client has various configuration values to tweak, but the defaults -/// are set to what is usually the most commonly desired value. -/// -/// The `Client` holds a connection pool internally, so it is advised that -/// you create one and reuse it. -/// -/// # Examples -/// -/// ```rust -/// # use reqwest::{Error, Client}; -/// # -/// # fn run() -> Result<(), Error> { -/// let client = Client::new()?; -/// let resp = client.get("http://httpbin.org/")?.send()?; -/// # drop(resp); -/// # Ok(()) -/// # } -/// -/// ``` +/// An asynchornous `Client` to make Requests with. #[derive(Clone)] pub struct Client { inner: Arc, } /// A `ClientBuilder` can be used to create a `Client` with custom configuration: -/// -/// - with hostname verification disabled -/// - with one or multiple custom certificates -/// -/// # Examples -/// -/// ``` -/// # use std::fs::File; -/// # use std::io::Read; -/// # fn build_client() -> Result<(), Box> { -/// // read a local binary DER encoded certificate -/// let mut buf = Vec::new(); -/// File::open("my-cert.der")?.read_to_end(&mut buf)?; -/// -/// // create a certificate -/// let cert = reqwest::Certificate::from_der(&buf)?; -/// -/// // get a client builder -/// let client = reqwest::ClientBuilder::new()? -/// .add_root_certificate(cert)? -/// .build()?; -/// # drop(client); -/// # Ok(()) -/// # } -/// ``` pub struct ClientBuilder { config: Option, } @@ -124,20 +79,16 @@ impl ClientBuilder { let tls = try_!(config.tls.build()); - /* - let mut tls_client = NativeTlsClient::from(tls_connector); - if !config.hostname_verification { - tls_client.danger_disable_hostname_verification(true); - } - */ - let proxies = Arc::new(config.proxies); - let hyper_client = create_hyper_client(tls, proxies.clone(), handle); - //let mut hyper_client = create_hyper_client(tls_client); + let mut connector = Connector::new(tls, proxies.clone(), handle); + if !config.hostname_verification { + connector.danger_disable_hostname_verification(); + } - //hyper_client.set_read_timeout(config.timeout); - //hyper_client.set_write_timeout(config.timeout); + let hyper_client = ::hyper::Client::configure() + .connector(connector) + .build(handle); Ok(Client { inner: Arc::new(ClientRef { diff --git a/src/connect.rs b/src/connect.rs index cf815c6..b2297bc 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -30,6 +30,10 @@ impl Connector { proxies: proxies, } } + + pub fn danger_disable_hostname_verification(&mut self) { + self.https.danger_disable_hostname_verification(true); + } } impl Service for Connector {