Disable hostname verification when option is enabled

Closes #153
This commit is contained in:
Sean McArthur
2017-06-28 11:03:28 -07:00
parent 478309e03f
commit 1785e0dc5d
3 changed files with 13 additions and 58 deletions

View File

@@ -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"

View File

@@ -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<ClientRef>,
}
/// 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<std::error::Error>> {
/// // 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<Config>,
}
@@ -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 {

View File

@@ -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 {