[Core] Bump hyper to ~0.12

This commit is contained in:
ashthespy 2021-01-23 22:21:42 +00:00
parent efabb03631
commit 6f5607d9ab
4 changed files with 20 additions and 21 deletions

View file

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

View file

@ -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<Url>,
ap_port: &Option<u16>,
) -> Box<dyn Future<Item = String, Error = Error>> {
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<E>(
handle: &Handle,
proxy: &Option<Url>,
ap_port: &Option<u16>,
) -> Box<dyn Future<Item = String, Error = E>>
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())

View file

@ -102,7 +102,7 @@ fn proxy_connect<T: AsyncWrite>(connection: T, connect_url: &str) -> WriteAll<T,
"CONNECT {0}:{1} HTTP/1.1\r\n\
\r\n",
uri.host().expect(&format!("No host in {}", uri)),
uri.port().expect(&format!("No port in {}", uri))
uri.port_u16().expect(&format!("No port in {}", uri))
)
.into_bytes();

View file

@ -54,8 +54,7 @@ impl Session {
cache: Option<Cache>,
handle: Handle,
) -> Box<dyn Future<Item = Session, Error = io::Error>> {
let access_point =
apresolve_or_fallback::<io::Error>(&handle, &config.proxy, &config.ap_port);
let access_point = apresolve_or_fallback::<io::Error>(&config.proxy, &config.ap_port);
let handle_ = handle.clone();
let proxy = config.proxy.clone();