From a2abebb256f8f918e2ebd7e55ed2cb16bb376b46 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Tue, 10 Dec 2024 16:57:38 +0100 Subject: [PATCH] feat(awc): replace trust dns by hickory dns --- awc/CHANGES.md | 1 + awc/Cargo.toml | 8 +++++--- awc/src/client/connector.rs | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 8a2a1ec43..a6c0cfd38 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -5,6 +5,7 @@ - Update `brotli` dependency to `7`. - Prevent panics on connection pool drop when Tokio runtime is shutdown early. - Minimum supported Rust version (MSRV) is now 1.75. +- Replace `trust-dns-resolver` with `hickory-resolver` for DNS resolution in awc when using `trust-dns` feature. ## 3.5.1 diff --git a/awc/Cargo.toml b/awc/Cargo.toml index c09f32ac8..7109cdcf7 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -83,8 +83,10 @@ compress-zstd = ["actix-http/compress-zstd", "__compress"] # Cookie parsing and cookie jar cookies = ["dep:cookie"] -# Use `trust-dns-resolver` crate as DNS resolver -trust-dns = ["trust-dns-resolver"] +# Use `trust-dns-resolver` crate as DNS resolver, deprecated in favor of `hickory-dns` which is a drop-in replacement +trust-dns = ["hickory-dns"] +# Use `hickory-dns-resolver` crate as DNS resolver +hickory-dns = ["hickory-resolver"] # Internal (PRIVATE!) features used to aid testing and checking feature status. # Don't rely on these whatsoever. They may disappear at anytime. @@ -130,7 +132,7 @@ tls-rustls-0_21 = { package = "rustls", version = "0.21", optional = true, featu tls-rustls-0_22 = { package = "rustls", version = "0.22", optional = true } tls-rustls-0_23 = { package = "rustls", version = "0.23", optional = true, default-features = false } -trust-dns-resolver = { version = "0.23", optional = true } +hickory-resolver = { version = "0.24.2", optional = true } [dev-dependencies] actix-http = { version = "3.7", features = ["openssl"] } diff --git a/awc/src/client/connector.rs b/awc/src/client/connector.rs index f3d443070..c9cc87052 100644 --- a/awc/src/client/connector.rs +++ b/awc/src/client/connector.rs @@ -1032,7 +1032,7 @@ where } } -#[cfg(not(feature = "trust-dns"))] +#[cfg(not(feature = "hickory-dns"))] mod resolver { use super::*; @@ -1041,12 +1041,12 @@ mod resolver { } } -#[cfg(feature = "trust-dns")] +#[cfg(feature = "hickory-dns")] mod resolver { use std::{cell::RefCell, net::SocketAddr}; use actix_tls::connect::Resolve; - use trust_dns_resolver::{ + use hickory_resolver::{ config::{ResolverConfig, ResolverOpts}, system_conf::read_system_conf, TokioAsyncResolver, @@ -1056,9 +1056,9 @@ mod resolver { pub(super) fn resolver() -> Resolver { // new type for impl Resolve trait for TokioAsyncResolver. - struct TrustDnsResolver(TokioAsyncResolver); + struct HickoryDnsResolver(TokioAsyncResolver); - impl Resolve for TrustDnsResolver { + impl Resolve for HickoryDnsResolver { fn lookup<'a>( &'a self, host: &'a str, @@ -1080,11 +1080,11 @@ mod resolver { // resolver struct is cached in thread local so new clients can reuse the existing instance thread_local! { - static TRUST_DNS_RESOLVER: RefCell> = const { RefCell::new(None) }; + static HICKORY_DNS_RESOLVER: RefCell> = const { RefCell::new(None) }; } - // get from thread local or construct a new trust-dns resolver. - TRUST_DNS_RESOLVER.with(|local| { + // get from thread local or construct a new hickory dns resolver. + HICKORY_DNS_RESOLVER.with(|local| { let resolver = local.borrow().as_ref().map(Clone::clone); match resolver { @@ -1094,15 +1094,15 @@ mod resolver { let (cfg, opts) = match read_system_conf() { Ok((cfg, opts)) => (cfg, opts), Err(err) => { - log::error!("Trust-DNS can not load system config: {err}"); + log::error!("Hickory-DNS can not load system config: {err}"); (ResolverConfig::default(), ResolverOpts::default()) } }; let resolver = TokioAsyncResolver::tokio(cfg, opts); - // box trust dns resolver and put it in thread local. - let resolver = Resolver::custom(TrustDnsResolver(resolver)); + // box hickory dns resolver and put it in thread local. + let resolver = Resolver::custom(HickoryDnsResolver(resolver)); *local.borrow_mut() = Some(resolver.clone()); resolver