Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use hyper::client::Client;
- use std::net::SocketAddr;
- const DEFAULT_HTTPS_DNS_WORKER_THREADS: usize = 1;
- pub trait Executor {
- }
- struct HyperExecutor<C> {
- inner: Client<C>
- }
- impl<C> HyperExecutor<C> {
- fn new(inner: Client<C>) -> Self {
- HyperExecutor { inner }
- }
- }
- impl<C> Executor for HyperExecutor<C> {
- }
- 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<SocketAddr> {
- hyper_socks2::Proxy::Socks5 {
- addrs: "host:port",
- auth: None
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement