Skip to content

Commit c285902

Browse files
authored
RUST-2219 Relax domain name parsing (#1399)
1 parent b720b29 commit c285902

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ impl Error {
290290
.into()
291291
}
292292

293+
#[cfg(feature = "dns-resolver")]
294+
pub(crate) fn from_resolve_proto_error(error: hickory_proto::error::ProtoError) -> Self {
295+
ErrorKind::DnsResolve {
296+
message: error.to_string(),
297+
}
298+
.into()
299+
}
300+
293301
pub(crate) fn is_non_timeout_network_error(&self) -> bool {
294302
matches!(self.kind.as_ref(), ErrorKind::Io(ref io_err) if io_err.kind() != std::io::ErrorKind::TimedOut)
295303
}

src/runtime/resolver.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hickory_resolver::{
22
config::ResolverConfig,
33
error::ResolveErrorKind,
44
lookup::{SrvLookup, TxtLookup},
5-
IntoName,
5+
Name,
66
};
77

88
use crate::error::{Error, Result};
@@ -25,17 +25,19 @@ impl AsyncResolver {
2525
}
2626

2727
impl AsyncResolver {
28-
pub async fn srv_lookup<N: IntoName>(&self, query: N) -> Result<SrvLookup> {
28+
pub async fn srv_lookup(&self, query: &str) -> Result<SrvLookup> {
29+
let name = Name::from_str_relaxed(query).map_err(Error::from_resolve_proto_error)?;
2930
let lookup = self
3031
.resolver
31-
.srv_lookup(query)
32+
.srv_lookup(name)
3233
.await
3334
.map_err(Error::from_resolve_error)?;
3435
Ok(lookup)
3536
}
3637

37-
pub async fn txt_lookup<N: IntoName>(&self, query: N) -> Result<Option<TxtLookup>> {
38-
let lookup_result = self.resolver.txt_lookup(query).await;
38+
pub async fn txt_lookup(&self, query: &str) -> Result<Option<TxtLookup>> {
39+
let name = Name::from_str_relaxed(query).map_err(Error::from_resolve_proto_error)?;
40+
let lookup_result = self.resolver.txt_lookup(name).await;
3941
match lookup_result {
4042
Ok(lookup) => Ok(Some(lookup)),
4143
Err(e) => match e.kind() {

0 commit comments

Comments
 (0)