1use std::error::Error;
19
20use hyper_dep::client::HttpConnector;
21use hyper_proxy::{Proxy, ProxyConnector};
22use hyper_tls::HttpsConnector;
23
24use crate::proxy::PROXY_CONFIG;
25
26pub type Connector = ProxyConnector<HttpsConnector<HttpConnector>>;
28
29pub fn connector() -> Result<Connector, Box<dyn Error + Send + Sync>> {
34 let mut connector = ProxyConnector::new(HttpsConnector::new())?;
35
36 if let Some(http_proxy) = PROXY_CONFIG.http_proxy() {
37 let matches = move |scheme: Option<&str>, host: Option<&str>, port| {
38 scheme == Some("http") && !PROXY_CONFIG.exclude(scheme, host, port)
39 };
40 connector.add_proxy(Proxy::new(matches, http_proxy.clone()));
41 }
42
43 if let Some(https_proxy) = PROXY_CONFIG.https_proxy() {
44 let matches = move |scheme: Option<&str>, host: Option<&str>, port| {
45 scheme == Some("https") && !PROXY_CONFIG.exclude(scheme, host, port)
46 };
47 connector.add_proxy(Proxy::new(matches, https_proxy.clone()));
48 }
49
50 if let Some(all_proxy) = PROXY_CONFIG.all_proxy() {
51 let matches = move |scheme: Option<&str>, host: Option<&str>, port| {
52 !PROXY_CONFIG.exclude(scheme, host, port)
53 };
54 connector.add_proxy(Proxy::new(matches, all_proxy.clone()));
55 }
56
57 Ok(connector)
58}