Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(awc): replace trust dns by hickory dns #3528

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions awc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions awc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"] }
Expand Down
22 changes: 11 additions & 11 deletions awc/src/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ where
}
}

#[cfg(not(feature = "trust-dns"))]
#[cfg(not(feature = "hickory-dns"))]
mod resolver {
use super::*;

Expand All @@ -1046,12 +1046,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,
Expand All @@ -1061,9 +1061,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,
Expand All @@ -1085,11 +1085,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<Option<Resolver>> = const { RefCell::new(None) };
static HICKORY_DNS_RESOLVER: RefCell<Option<Resolver>> = 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 {
Expand All @@ -1099,15 +1099,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
Expand Down
Loading