diff --git a/core/Cargo.toml b/core/Cargo.toml index 8511878c..d2eec63f 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -19,8 +19,8 @@ bytes = "0.4" error-chain = { version = "0.12", default_features = false } futures = "0.1" httparse = "1.3" -hyper = "0.11" -hyper-proxy = { version = "0.4", default_features = false } +hyper = "0.12" +hyper-proxy = { version = "0.5", default_features = false } lazy_static = "1.3" log = "0.4" num-bigint = "0.3" diff --git a/core/src/apresolve.rs b/core/src/apresolve.rs index 94d94244..bea23318 100644 --- a/core/src/apresolve.rs +++ b/core/src/apresolve.rs @@ -3,11 +3,10 @@ const APRESOLVE_ENDPOINT: &'static str = "http://apresolve.spotify.com/"; use futures::{Future, Stream}; use hyper::client::HttpConnector; -use hyper::{self, Client, Method, Request, Uri}; +use hyper::{self, Client, Request, Uri}; use hyper_proxy::{Intercept, Proxy, ProxyConnector}; use serde_json; use std::str::FromStr; -use tokio_core::reactor::Handle; use url::Url; error_chain! {} @@ -18,35 +17,37 @@ pub struct APResolveData { } fn apresolve( - handle: &Handle, proxy: &Option, ap_port: &Option, ) -> Box> { let url = Uri::from_str(APRESOLVE_ENDPOINT).expect("invalid AP resolve URL"); let use_proxy = proxy.is_some(); - let mut req = Request::new(Method::Get, url.clone()); + // let mut req = Request::new(url.clone()); + let mut req = Request::get(url.clone()) + .body(hyper::Body::from(vec![])) + .unwrap(); let response = match *proxy { Some(ref val) => { let proxy_url = Uri::from_str(val.as_str()).expect("invalid http proxy"); let proxy = Proxy::new(Intercept::All, proxy_url); - let connector = HttpConnector::new(4, handle); + let connector = HttpConnector::new(4); let proxy_connector = ProxyConnector::from_proxy_unsecured(connector, proxy); if let Some(headers) = proxy_connector.http_headers(&url) { - req.headers_mut().extend(headers.iter()); - req.set_proxy(true); + req.headers_mut().extend(headers.clone().into_iter()); + // req.set_proxy(true); } - let client = Client::configure().connector(proxy_connector).build(handle); + let client = Client::builder().build(proxy_connector); client.request(req) } _ => { - let client = Client::new(handle); + let client = Client::new(); client.request(req) } }; let body = response.and_then(|response| { - response.body().fold(Vec::new(), |mut acc, chunk| { + response.into_body().fold(Vec::new(), |mut acc, chunk| { acc.extend_from_slice(chunk.as_ref()); Ok::<_, hyper::Error>(acc) }) @@ -64,13 +65,13 @@ fn apresolve( let mut aps = data.ap_list.iter().filter(|ap| { if p.is_some() { Uri::from_str(ap).ok().map_or(false, |uri| { - uri.port().map_or(false, |port| port == p.unwrap()) + uri.port_u16().map_or(false, |port| port == p.unwrap()) }) } else if use_proxy { // It is unlikely that the proxy will accept CONNECT on anything other than 443. - Uri::from_str(ap) - .ok() - .map_or(false, |uri| uri.port().map_or(false, |port| port == 443)) + Uri::from_str(ap).ok().map_or(false, |uri| { + uri.port_u16().map_or(false, |port| port == 443) + }) } else { true } @@ -84,14 +85,13 @@ fn apresolve( } pub(crate) fn apresolve_or_fallback( - handle: &Handle, proxy: &Option, ap_port: &Option, ) -> Box> where E: 'static, { - let ap = apresolve(handle, proxy, ap_port).or_else(|e| { + let ap = apresolve(proxy, ap_port).or_else(|e| { warn!("Failed to resolve Access Point: {}", e.description()); warn!("Using fallback \"{}\"", AP_FALLBACK); Ok(AP_FALLBACK.into()) diff --git a/core/src/proxytunnel.rs b/core/src/proxytunnel.rs index b1363846..e8fb1373 100644 --- a/core/src/proxytunnel.rs +++ b/core/src/proxytunnel.rs @@ -102,7 +102,7 @@ fn proxy_connect(connection: T, connect_url: &str) -> WriteAll, handle: Handle, ) -> Box> { - let access_point = - apresolve_or_fallback::(&handle, &config.proxy, &config.ap_port); + let access_point = apresolve_or_fallback::(&config.proxy, &config.ap_port); let handle_ = handle.clone(); let proxy = config.proxy.clone();