1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-16 21:26:34 +00:00

feat(awc): replace trust dns by hickory dns

This commit is contained in:
Joel Wurtz 2024-12-10 16:57:38 +01:00
parent 8115c818c1
commit a2abebb256
No known key found for this signature in database
GPG key ID: ED264D1967A51B0D
3 changed files with 17 additions and 14 deletions

View file

@ -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

View file

@ -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"] }

View file

@ -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<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 {
@ -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