refactor DNS resolver construction
- System Conf is read as `ClientBuilder::build()` time, providing the error earlier. - If there is an error reading the resolve system conf, a better error is reported. - Resolver only needs to lock a mutex once to spawn the background task, instead of every single `resolve` call.
This commit is contained in:
11
src/error.rs
11
src/error.rs
@@ -140,6 +140,7 @@ impl Error {
|
||||
Kind::NativeTls(ref e) => Some(e),
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
Kind::Rustls(ref e) => Some(e),
|
||||
Kind::DnsSystemConf(ref e) => Some(e),
|
||||
Kind::Io(ref e) => Some(e),
|
||||
Kind::UrlEncoded(ref e) => Some(e),
|
||||
Kind::Json(ref e) => Some(e),
|
||||
@@ -237,6 +238,9 @@ impl fmt::Display for Error {
|
||||
Kind::NativeTls(ref e) => fmt::Display::fmt(e, f),
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
Kind::Rustls(ref e) => fmt::Display::fmt(e, f),
|
||||
Kind::DnsSystemConf(ref e) => {
|
||||
write!(f, "failed to load DNS system conf: {}", e)
|
||||
},
|
||||
Kind::Io(ref e) => fmt::Display::fmt(e, f),
|
||||
Kind::UrlEncoded(ref e) => fmt::Display::fmt(e, f),
|
||||
Kind::Json(ref e) => fmt::Display::fmt(e, f),
|
||||
@@ -268,6 +272,7 @@ impl StdError for Error {
|
||||
Kind::NativeTls(ref e) => e.description(),
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
Kind::Rustls(ref e) => e.description(),
|
||||
Kind::DnsSystemConf(_) => "failed to load DNS system conf",
|
||||
Kind::Io(ref e) => e.description(),
|
||||
Kind::UrlEncoded(ref e) => e.description(),
|
||||
Kind::Json(ref e) => e.description(),
|
||||
@@ -291,6 +296,7 @@ impl StdError for Error {
|
||||
Kind::NativeTls(ref e) => e.cause(),
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
Kind::Rustls(ref e) => e.cause(),
|
||||
Kind::DnsSystemConf(ref e) => e.cause(),
|
||||
Kind::Io(ref e) => e.cause(),
|
||||
Kind::UrlEncoded(ref e) => e.cause(),
|
||||
Kind::Json(ref e) => e.cause(),
|
||||
@@ -316,6 +322,7 @@ pub(crate) enum Kind {
|
||||
NativeTls(::native_tls::Error),
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
Rustls(::rustls::TLSError),
|
||||
DnsSystemConf(io::Error),
|
||||
Io(io::Error),
|
||||
UrlEncoded(::serde_urlencoded::ser::Error),
|
||||
Json(::serde_json::Error),
|
||||
@@ -489,6 +496,10 @@ pub(crate) fn url_bad_scheme(url: Url) -> Error {
|
||||
Error::new(Kind::UrlBadScheme, Some(url))
|
||||
}
|
||||
|
||||
pub(crate) fn dns_system_conf(io: io::Error) -> Error {
|
||||
Error::new(Kind::DnsSystemConf(io), None)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user