Repository: seanmonstar/reqwest (language: rust)

Issue:
Disable `trust-dns` on Mac too
I suggest to disable `trust-dns` on Mac too, as in https://github.com/seanmonstar/reqwest/commit/23e13304ef60be061da5199cd8d12810eda62785

Why?

1) `trust-dns` panics for certain domain names in `/etc/resolve.conf`, see https://github.com/seanmonstar/reqwest/issues/435 This seems to affect at least everyone trying to use a Speedport modem from a Unix-like OS.

2) if you disable Wifi on a Mac, there is no `/etc/resolve.conf` file anymore, and `trust-dns` panics with `Error: Error { kind: DnsSystemConf(Os { code: 2, kind: NotFound, message: "No such file or directory" }), url: None }` which prevents you to access URLs that do not even need DNS like `http://127.0.0.1`. This affects every Mac user using Wifi.


Discussion / hints:

Fix patch:
diff --git a/.travis.yml b/.travis.yml
index 572e77dee..85db81b32 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,6 +26,9 @@ matrix:
         - rust: stable
           env: FEATURES="--features hyper-011"
 
+        - rust: stable
+          env: FEATURES="--features trust-dns"
+
         # android
         - rust: stable
           env: TARGET=aarch64-linux-android
diff --git a/Cargo.toml b/Cargo.toml
index a750d379e..54d8404e7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -31,6 +31,7 @@ tokio-executor = "0.1.4" # a minimum version so trust-dns-resolver compiles
 tokio-io = "0.1"
 tokio-threadpool = "0.1.8" # a minimum version so tokio compiles
 tokio-timer = "0.2.6" # a minimum version so trust-dns-resolver compiles
+trust-dns-resolver = { version = "0.10", optional = true }
 url = "1.2"
 uuid = { version = "0.7", features = ["v4"] }
 hyper-rustls = { version = "0.15", optional = true }
@@ -38,12 +39,10 @@ tokio-rustls = { version = "0.8", optional = true }
 webpki-roots = { version = "0.15", optional = true }
 rustls = { version = "0.14", features = ["dangerous_configuration"], optional = true }
 
-[target.'cfg(not(any(target_os = "android", windows)))'.dependencies]
-trust-dns-resolver = "0.10"
-
 [dev-dependencies]
 env_logger = "0.6"
 serde_derive = "1.0"
+tokio-tcp = "0.1"
 
 [features]
 default = ["default-tls"]
@@ -55,6 +54,8 @@ default-tls-vendored = ["default-tls", "native-tls/vendored"]
 
 rustls-tls = ["hyper-rustls", "tokio-rustls", "webpki-roots", "rustls", "tls"]
 
+trust-dns = ["trust-dns-resolver"]
+
 hyper-011 = ["hyper-old-types"]
 
 [package.metadata.docs.rs]
diff --git a/src/connect.rs b/src/connect.rs
index 48c26e1c5..86f512ff3 100644
--- a/src/connect.rs
+++ b/src/connect.rs
@@ -13,13 +13,13 @@ use bytes::BufMut;
 use std::io;
 use std::sync::Arc;
 
-#[cfg(not(any(target_os = "android", windows)))]
+#[cfg(feature = "trust-dns")]
 use dns::TrustDnsResolver;
 use Proxy;
 
-#[cfg(not(any(target_os = "android", windows)))]
+#[cfg(feature = "trust-dns")]
 type HttpConnector = ::hyper::client::HttpConnector<TrustDnsResolver>;
-#[cfg(any(target_os = "android", windows))]
+#[cfg(not(feature = "trust-dns"))]
 type HttpConnector = ::hyper::client::HttpConnector;
 
 
@@ -74,14 +74,14 @@ impl Connector {
     }
 }
 
-#[cfg(not(any(target_os = "android", windows)))]
+#[cfg(feature = "trust-dns")]
 fn http_connector() -> ::Result<HttpConnector> {
     TrustDnsResolver::new()
         .map(HttpConnector::new_with_resolver)
         .map_err(::error::dns_system_conf)
 }
 
-#[cfg(any(target_os = "android", windows))]
+#[cfg(not(feature = "trust-dns"))]
 fn http_connector() -> ::Result<HttpConnector> {
     Ok(HttpConnector::new(4))
 }
@@ -279,12 +279,14 @@ fn tunnel_eof() -> io::Error {
 #[cfg(feature = "tls")]
 #[cfg(test)]
 mod tests {
+    extern crate tokio_tcp;
+
     use std::io::{Read, Write};
     use std::net::TcpListener;
     use std::thread;
     use futures::Future;
     use tokio::runtime::current_thread::Runtime;
-    use tokio::net::TcpStream;
+    use self::tokio_tcp::TcpStream;
     use super::tunnel;
     use proxy;
 
diff --git a/src/error.rs b/src/error.rs
index 7107ef4c0..b3676192c 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -140,7 +140,7 @@ impl Error {
             Kind::NativeTls(ref e) => Some(e),
             #[cfg(feature = "rustls-tls")]
             Kind::Rustls(ref e) => Some(e),
-            #[cfg(not(any(target_os = "android", windows)))]
+            #[cfg(feature = "trust-dns")]
             Kind::DnsSystemConf(ref e) => Some(e),
             Kind::Io(ref e) => Some(e),
             Kind::UrlEncoded(ref e) => Some(e),
@@ -239,7 +239,7 @@ 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),
-            #[cfg(not(any(target_os = "android", windows)))]
+            #[cfg(feature = "trust-dns")]
             Kind::DnsSystemConf(ref e) => {
                 write!(f, "failed to load DNS system conf: {}", e)
             },
@@ -274,7 +274,7 @@ impl StdError for Error {
             Kind::NativeTls(ref e) => e.description(),
             #[cfg(feature = "rustls-tls")]
             Kind::Rustls(ref e) => e.description(),
-            #[cfg(not(any(target_os = "android", windows)))]
+            #[cfg(feature = "trust-dns")]
             Kind::DnsSystemConf(_) => "failed to load DNS system conf",
             Kind::Io(ref e) => e.description(),
             Kind::UrlEncoded(ref e) => e.description(),
@@ -299,7 +299,7 @@ impl StdError for Error {
             Kind::NativeTls(ref e) => e.cause(),
             #[cfg(feature = "rustls-tls")]
             Kind::Rustls(ref e) => e.cause(),
-            #[cfg(not(any(target_os = "android", windows)))]
+            #[cfg(feature = "trust-dns")]
             Kind::DnsSystemConf(ref e) => e.cause(),
             Kind::Io(ref e) => e.cause(),
             Kind::UrlEncoded(ref e) => e.cause(),
@@ -326,7 +326,7 @@ pub(crate) enum Kind {
     NativeTls(::native_tls::Error),
     #[cfg(feature = "rustls-tls")]
     Rustls(::rustls::TLSError),
-    #[cfg(not(any(target_os = "android", windows)))]
+    #[cfg(feature = "trust-dns")]
     DnsSystemConf(io::Error),
     Io(io::Error),
     UrlEncoded(::serde_urlencoded::ser::Error),
@@ -501,7 +501,7 @@ pub(crate) fn url_bad_scheme(url: Url) -> Error {
     Error::new(Kind::UrlBadScheme, Some(url))
 }
 
-#[cfg(not(any(target_os = "android", windows)))]
+#[cfg(feature = "trust-dns")]
 pub(crate) fn dns_system_conf(io: io::Error) -> Error {
     Error::new(Kind::DnsSystemConf(io), None)
 }
diff --git a/src/lib.rs b/src/lib.rs
index 107d3eb12..bffaa7179 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -155,6 +155,8 @@
 //!   `native-tls` library to connect over HTTPS.
 //! - **default-tls-vendored**: Enables the `vendored` feature of `native-tls`.
 //! - **rustls-tls**: Provides TLS support via the `rustls` library.
+//! - **trust-dns**: Enables a trust-dns async resolver instead of default
+//!   threadpool using `getaddrinfo`.
 //! - **hyper-011**: Provides support for hyper's old typed headers.
 //!
 //!
@@ -196,7 +198,7 @@ extern crate serde_urlencoded;
 extern crate tokio;
 #[cfg_attr(feature = "default-tls", macro_use)]
 extern crate tokio_io;
-#[cfg(not(any(target_os = "android", windows)))]
+#[cfg(feature = "trust-dns")]
 extern crate trust_dns_resolver;
 extern crate url;
 extern crate uuid;
@@ -238,7 +240,7 @@ mod connect;
 mod connect_async;
 mod body;
 mod client;
-#[cfg(not(any(target_os = "android", windows)))]
+#[cfg(feature = "trust-dns")]
 mod dns;
 mod into_url;
 mod proxy;


Test patch: