使用 DNS 分流

This commit is contained in:
2024-02-07 22:19:43 +08:00
parent 95b4b8b947
commit 9ee02e9312
13 changed files with 247 additions and 70 deletions

View File

@ -21,12 +21,13 @@ pub struct RustHttpResponse {
lazy_static! {
static ref DEFAULT_HEADER: RwLock<HeaderMap> = RwLock::from(HeaderMap::new());
static ref DNS_CLIENT : Arc<dns::MyHickoryDnsResolver> = Arc::from(dns::MyHickoryDnsResolver::default());
static ref HTTP_CLIENT: reqwest::Client = {
reqwest::Client::builder()
.use_rustls_tls()
.connect_timeout(Duration::from_secs(10))
.timeout(Duration::from_secs(10))
.dns_resolver(Arc::from(dns::MyHickoryDnsResolver::default()))
.dns_resolver(DNS_CLIENT.clone())
.build()
.unwrap()
};
@ -83,6 +84,10 @@ pub async fn fetch(
Ok(resp)
}
pub async fn dns_lookup_txt(name: String) -> anyhow::Result<Vec<String>> {
DNS_CLIENT.lookup_txt(name).await
}
fn _reade_resp_header(r_header: &HeaderMap) -> HashMap<String, String> {
let mut resp_headers = HashMap::new();
for ele in r_header {