remove proxy handling in favor of hyper-proxy crate
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
use std::fmt;
|
||||
use std::{io, fmt};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use bytes::Bytes;
|
||||
use futures::{Async, Future, Poll};
|
||||
use hyper::client::FutureResponse;
|
||||
use hyper::client::{Connect, FutureResponse, HttpConnector};
|
||||
use hyper::header::{Headers, Location, Referer, UserAgent, Accept, Encoding,
|
||||
AcceptEncoding, Range, qitem};
|
||||
use hyper_tls::HttpsConnector;
|
||||
use native_tls::{TlsConnector, TlsConnectorBuilder};
|
||||
use tokio_core::reactor::Handle;
|
||||
|
||||
@@ -14,7 +15,6 @@ use tokio_core::reactor::Handle;
|
||||
use super::body;
|
||||
use super::request::{self, Request, RequestBuilder};
|
||||
use super::response::{self, Response};
|
||||
use connect::Connector;
|
||||
use into_url::to_uri;
|
||||
use redirect::{self, RedirectPolicy, check_redirect, remove_sensitive_headers};
|
||||
use {Certificate, Identity, IntoUrl, Method, proxy, Proxy, StatusCode, Url};
|
||||
@@ -65,7 +65,8 @@ struct Config {
|
||||
gzip: bool,
|
||||
headers: Headers,
|
||||
hostname_verification: bool,
|
||||
proxies: Vec<Proxy>,
|
||||
// TODO: investigate Vec<Proxy> as before
|
||||
proxy: Proxy,
|
||||
redirect_policy: RedirectPolicy,
|
||||
referer: bool,
|
||||
timeout: Option<Duration>,
|
||||
@@ -87,7 +88,7 @@ impl ClientBuilder {
|
||||
gzip: true,
|
||||
headers: headers,
|
||||
hostname_verification: true,
|
||||
proxies: Vec::new(),
|
||||
proxy: Proxy::empty(),
|
||||
redirect_policy: RedirectPolicy::default(),
|
||||
referer: true,
|
||||
timeout: None,
|
||||
@@ -122,14 +123,14 @@ impl ClientBuilder {
|
||||
.take()
|
||||
.expect("ClientBuilder cannot be reused after building a Client");
|
||||
|
||||
let tls = try_!(config.tls.build());
|
||||
|
||||
let proxies = Arc::new(config.proxies);
|
||||
|
||||
let mut connector = Connector::new(config.dns_threads, tls, proxies.clone(), handle);
|
||||
let mut https_connector = try_!(HttpsConnector::new(config.dns_threads, handle));
|
||||
if !config.hostname_verification {
|
||||
connector.danger_disable_hostname_verification();
|
||||
https_connector.danger_disable_hostname_verification(true);
|
||||
}
|
||||
let mut connector = config.proxy.inner.with_connector(https_connector);
|
||||
let tls = try_!(config.tls.build());
|
||||
connector.set_tls(Some(tls));
|
||||
|
||||
let hyper_client = ::hyper::Client::configure()
|
||||
.connector(connector)
|
||||
@@ -140,7 +141,6 @@ impl ClientBuilder {
|
||||
gzip: config.gzip,
|
||||
hyper: hyper_client,
|
||||
headers: config.headers,
|
||||
proxies: proxies,
|
||||
redirect_policy: config.redirect_policy,
|
||||
referer: config.referer,
|
||||
}),
|
||||
@@ -222,7 +222,7 @@ impl ClientBuilder {
|
||||
#[inline]
|
||||
pub fn proxy(&mut self, proxy: Proxy) -> &mut ClientBuilder {
|
||||
if let Some(config) = config_mut(&mut self.config, &self.err) {
|
||||
config.proxies.push(proxy);
|
||||
config.proxy = proxy;
|
||||
}
|
||||
self
|
||||
}
|
||||
@@ -276,7 +276,7 @@ fn config_mut<'a>(config: &'a mut Option<Config>, err: &Option<::Error>) -> Opti
|
||||
}
|
||||
}
|
||||
|
||||
type HyperClient = ::hyper::Client<Connector>;
|
||||
type HyperClient = ::hyper::Client<::hyper_proxy::Proxy<HttpsConnector<HttpConnector>>>;
|
||||
|
||||
impl Client {
|
||||
/// Constructs a new `Client`.
|
||||
@@ -412,12 +412,6 @@ impl Client {
|
||||
reusable
|
||||
});
|
||||
|
||||
if proxy::is_proxied(&self.inner.proxies, &url) {
|
||||
if uri.scheme() == Some("http") {
|
||||
req.set_proxy(true);
|
||||
}
|
||||
}
|
||||
|
||||
let in_flight = self.inner.hyper.request(req);
|
||||
|
||||
Pending {
|
||||
@@ -458,7 +452,6 @@ struct ClientRef {
|
||||
gzip: bool,
|
||||
headers: Headers,
|
||||
hyper: HyperClient,
|
||||
proxies: Arc<Vec<Proxy>>,
|
||||
redirect_policy: RedirectPolicy,
|
||||
referer: bool,
|
||||
}
|
||||
@@ -556,11 +549,6 @@ impl Future for PendingRequest {
|
||||
if let Some(Some(ref body)) = self.body {
|
||||
req.set_body(body.clone());
|
||||
}
|
||||
if proxy::is_proxied(&self.client.proxies, &self.url) {
|
||||
if uri.scheme() == Some("http") {
|
||||
req.set_proxy(true);
|
||||
}
|
||||
}
|
||||
self.in_flight = self.client.hyper.request(req);
|
||||
continue;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user