@@ -13,7 +13,7 @@ categories = ["web-programming::http-client"]
|
|||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
futures = "0.1.14"
|
futures = "0.1.14"
|
||||||
hyper = "0.11"
|
hyper = "0.11"
|
||||||
hyper-tls = "0.1.1"
|
hyper-tls = "0.1.2"
|
||||||
libflate = "0.1.5"
|
libflate = "0.1.5"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
native-tls = "0.1"
|
native-tls = "0.1"
|
||||||
|
|||||||
@@ -22,58 +22,13 @@ use {Certificate, IntoUrl, Method, proxy, Proxy, StatusCode, Url};
|
|||||||
static DEFAULT_USER_AGENT: &'static str =
|
static DEFAULT_USER_AGENT: &'static str =
|
||||||
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
/// A `Client` to make Requests with.
|
/// An asynchornous `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(())
|
|
||||||
/// # }
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
inner: Arc<ClientRef>,
|
inner: Arc<ClientRef>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `ClientBuilder` can be used to create a `Client` with custom configuration:
|
/// 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 {
|
pub struct ClientBuilder {
|
||||||
config: Option<Config>,
|
config: Option<Config>,
|
||||||
}
|
}
|
||||||
@@ -124,20 +79,16 @@ impl ClientBuilder {
|
|||||||
|
|
||||||
let tls = try_!(config.tls.build());
|
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 proxies = Arc::new(config.proxies);
|
||||||
|
|
||||||
let hyper_client = create_hyper_client(tls, proxies.clone(), handle);
|
let mut connector = Connector::new(tls, proxies.clone(), handle);
|
||||||
//let mut hyper_client = create_hyper_client(tls_client);
|
if !config.hostname_verification {
|
||||||
|
connector.danger_disable_hostname_verification();
|
||||||
|
}
|
||||||
|
|
||||||
//hyper_client.set_read_timeout(config.timeout);
|
let hyper_client = ::hyper::Client::configure()
|
||||||
//hyper_client.set_write_timeout(config.timeout);
|
.connector(connector)
|
||||||
|
.build(handle);
|
||||||
|
|
||||||
Ok(Client {
|
Ok(Client {
|
||||||
inner: Arc::new(ClientRef {
|
inner: Arc::new(ClientRef {
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ impl Connector {
|
|||||||
proxies: proxies,
|
proxies: proxies,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn danger_disable_hostname_verification(&mut self) {
|
||||||
|
self.https.danger_disable_hostname_verification(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service for Connector {
|
impl Service for Connector {
|
||||||
|
|||||||
Reference in New Issue
Block a user