diff --git a/examples/client.py b/examples/client.py index 4ee1cdd..92ec3d2 100644 --- a/examples/client.py +++ b/examples/client.py @@ -30,7 +30,6 @@ async def main(): client = Client( impersonate=Impersonate.Firefox133, user_agent="rnet", - async_dns=True, proxies=[ Proxy.http("socks5h://abc:def@127.0.0.1:1080"), Proxy.https(url="socks5h://127.0.0.1:1080", username="abc", password="def"), diff --git a/src/client.rs b/src/client.rs index 8f79f81..1406bca 100644 --- a/src/client.rs +++ b/src/client.rs @@ -13,7 +13,6 @@ use arc_swap::{ArcSwap, Guard}; use pyo3::prelude::*; use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods}; use rquest::{ - dns::LookupIpStrategy, header::{HeaderMap, HeaderName, HeaderValue}, redirect::Policy, Url, @@ -29,6 +28,11 @@ macro_rules! apply_option { $builder = $builder.$method(value); } }; + (apply_if_ok, $builder:expr, $result:expr, $method:ident) => { + if let Ok(value) = $result() { + $builder = $builder.$method(value); + } + }; (apply_if_some_ref, $builder:expr, $option:expr, $method:ident) => { if let Some(value) = $option.take() { $builder = $builder.$method(&value); @@ -80,7 +84,9 @@ impl Client { /// ``` pub fn default() -> &'static Self { static CLIENT: LazyLock = LazyLock::new(|| { - rquest::Client::builder() + let mut builder = rquest::Client::builder(); + apply_option!(apply_if_ok, builder, dns::get_or_try_init, dns_resolver); + builder .no_hickory_dns() .no_keepalive() .build() @@ -576,10 +582,7 @@ impl Client { apply_option!(apply_if_some, builder, params.cookie_store, cookie_store); // Async resolver options. - if params.async_dns.unwrap_or(false) { - let hickory_dns_resolver = dns::get_or_try_init(LookupIpStrategy::Ipv4AndIpv6)?; - builder = builder.dns_resolver(hickory_dns_resolver); - } + apply_option!(apply_if_ok, builder, dns::get_or_try_init, dns_resolver); // Timeout options. apply_option!( diff --git a/src/dns.rs b/src/dns.rs index 488c9ee..6ed3242 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -27,15 +27,12 @@ use std::sync::{Arc, OnceLock}; /// /// let resolver = get_or_try_init(LookupIpStrategy::default()).unwrap(); /// ``` -pub fn get_or_try_init(strategy: S) -> crate::Result> -where - S: Into>, -{ +pub fn get_or_try_init() -> crate::Result> { static DNS_RESOLVER: OnceLock, &'static str>> = OnceLock::new(); DNS_RESOLVER .get_or_init(move || { - HickoryDnsResolver::new(strategy.into()) + HickoryDnsResolver::new(LookupIpStrategy::Ipv4AndIpv6) .map(Arc::new) .map_err(|err| { #[cfg(feature = "logging")] diff --git a/src/param/client.rs b/src/param/client.rs index add269b..6700842 100644 --- a/src/param/client.rs +++ b/src/param/client.rs @@ -76,10 +76,6 @@ pub struct ClientParams { #[pyo3(get)] pub cookie_store: Option, - /// Whether to use async DNS resolver. - #[pyo3(get)] - pub async_dns: Option, - // ========= Timeout options ========= /// The timeout to use for the request. (in seconds) #[pyo3(get)] @@ -259,7 +255,6 @@ impl<'py> FromPyObject<'py> for ClientParams { extract_option!(ob, params, referer); extract_option!(ob, params, allow_redirects); extract_option!(ob, params, cookie_store); - extract_option!(ob, params, async_dns); extract_option!(ob, params, timeout); extract_option!(ob, params, connect_timeout);