use hyper::client::Client; use std::net::SocketAddr; const DEFAULT_HTTPS_DNS_WORKER_THREADS: usize = 1; pub trait Executor { } struct HyperExecutor { inner: Client } impl HyperExecutor { fn new(inner: Client) -> Self { HyperExecutor { inner } } } impl Executor for HyperExecutor { } fn default_executor() -> impl Executor { let connector = hyper_tls::HttpsConnector::new(DEFAULT_HTTPS_DNS_WORKER_THREADS).unwrap(); let client = Client::builder().build(connector); HyperExecutor::new(client) } fn socks_proxy_executor(proxy: &str) -> impl Executor { let client = Client::builder().build(hyper_socks2::Connector::new(parse_socks_proxy(proxy))); HyperExecutor::new(client) } fn http_proxy_executor() -> impl Executor { let uri = "http://my-proxy:8080".parse().unwrap(); let mut proxy = hyper_proxy::Proxy::new(hyper_proxy::Intercept::All, uri); proxy.set_authorization(typed_headers::Credentials::basic("John Doe", "Agent1234").unwrap()); let connector = hyper_tls::HttpsConnector::new(DEFAULT_HTTPS_DNS_WORKER_THREADS).unwrap(); let proxy_connector = hyper_proxy::ProxyConnector::from_proxy(connector, proxy).unwrap(); let client = Client::builder().build(proxy_connector); HyperExecutor::new(client) } fn parse_socks_proxy(dsn: &str) -> hyper_socks2::Proxy { hyper_socks2::Proxy::Socks5 { addrs: "host:port", auth: None } }