use hyper-tls and hyper-trust-dns as http(s) clients

This commit is contained in:
Jun Kurihara 2022-06-16 20:01:26 -04:00
commit 8fff4f4088
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
4 changed files with 138 additions and 80 deletions

View file

@ -1,5 +1,8 @@
use crate::{acceptor::PacketAcceptor, error::*, globals::Globals, log::*};
use futures::future::select_all;
use hyper::Client;
#[cfg(feature = "forward-hyper-trust-dns")]
use hyper_trust_dns::TrustDnsResolver;
use std::sync::Arc;
#[derive(Debug, Clone)]
@ -11,9 +14,16 @@ impl Proxy {
let addresses = self.globals.listen_addresses.clone();
let futures = select_all(addresses.into_iter().map(|addr| {
info!("Listen address: {:?}", addr);
#[cfg(feature = "forward-hyper-trust-dns")]
let connector = TrustDnsResolver::default().into_rustls_webpki_https_connector();
#[cfg(not(feature = "forward-hyper-trust-dns"))]
let connector = hyper_tls::HttpsConnector::new();
let acceptor = PacketAcceptor {
listening_on: addr,
globals: self.globals.clone(),
forwarder: Client::builder().build::<_, hyper::Body>(connector),
};
self.globals.runtime_handle.spawn(acceptor.start())
}));