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:
Sean McArthur
2019-01-10 11:17:09 -08:00
parent b129ab0bb4
commit b71787be86
6 changed files with 83 additions and 53 deletions

View File

@@ -112,7 +112,8 @@ impl ClientBuilder {
///
/// # Errors
///
/// This method fails if TLS backend cannot be initialized.
/// This method fails if TLS backend cannot be initialized, or the resolver
/// cannot load the system configuration.
pub fn build(self) -> ::Result<Client> {
let config = self.config;
let proxies = Arc::new(config.proxies);
@@ -208,7 +209,7 @@ impl ClientBuilder {
}
#[cfg(not(feature = "tls"))]
Connector::new(proxies.clone())
Connector::new(proxies.clone())?
};
let hyper_client = ::hyper::Client::builder()
@@ -362,13 +363,15 @@ impl Client {
///
/// # Panics
///
/// This method panics if TLS backend cannot be created or
/// initialized. Use `Client::builder()` if you wish to handle the failure
/// as an `Error` instead of panicking.
/// This method panics if TLS backend cannot initialized, or the resolver
/// cannot load the system configuration.
///
/// Use `Client::builder()` if you wish to handle the failure as an `Error`
/// instead of panicking.
pub fn new() -> Client {
ClientBuilder::new()
.build()
.expect("TLS failed to initialize")
.expect("Client::new()")
}
/// Creates a `ClientBuilder` to configure a `Client`.