Use the custom HTTP transport when any HTTP settings are present
authorJake Goulding <jake.goulding@integer32.com>
Mon, 11 Dec 2017 00:31:55 +0000 (19:31 -0500)
committerJake Goulding <jake.goulding@integer32.com>
Thu, 14 Dec 2017 19:36:06 +0000 (13:36 -0600)
src/bin/cargo.rs
src/cargo/ops/mod.rs
src/cargo/ops/registry.rs

index e92bcdbe5ff3ba0231e62c18d31f377c8eb0bac9..53025a23583164284c4fff1d5ddc1fc1a60e3e13 100644 (file)
@@ -398,10 +398,11 @@ fn search_directories(config: &Config) -> Vec<PathBuf> {
 }
 
 fn init_git_transports(config: &Config) {
-    // Only use a custom transport if a proxy is configured, right now libgit2
-    // doesn't support proxies and we have to use a custom transport in this
-    // case. The custom transport, however, is not as well battle-tested.
-    match cargo::ops::http_proxy_exists(config) {
+    // Only use a custom transport if any HTTP options are specified,
+    // such as proxies or custom certificate authorities. The custom
+    // transport, however, is not as well battle-tested.
+
+    match cargo::ops::needs_custom_http_transport(config) {
         Ok(true) => {}
         _ => return,
     }
index fa155b3f6a6f6d32a250a64fecb1fab320d31a23..7c4a33d4ba278a41ad9c25168a08e8ffe216d1f7 100644 (file)
@@ -17,7 +17,7 @@ pub use self::lockfile::{load_pkg_lockfile, write_pkg_lockfile};
 pub use self::cargo_test::{run_tests, run_benches, TestOptions};
 pub use self::cargo_package::{package, PackageOpts};
 pub use self::registry::{publish, registry_configuration, RegistryConfig};
-pub use self::registry::{registry_login, search, http_proxy_exists, http_handle};
+pub use self::registry::{registry_login, search, needs_custom_http_transport, http_handle};
 pub use self::registry::{modify_owners, yank, OwnersOptions, PublishOpts};
 pub use self::registry::configure_http_handle;
 pub use self::cargo_fetch::fetch;
index 122837b46bde04883841dedc54b71d91206e5919..bf6ba8135b72ae1188ada03c3f6dc463affc4790 100644 (file)
@@ -277,6 +277,15 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
     Ok(handle)
 }
 
+pub fn needs_custom_http_transport(config: &Config) -> CargoResult<bool> {
+    let proxy_exists = http_proxy_exists(config)?;
+    let timeout = http_timeout(config)?;
+    let cainfo = config.get_path("http.cainfo")?;
+    let check_revoke = config.get_bool("http.check-revoke")?;
+
+    Ok(proxy_exists || timeout.is_some() || cainfo.is_some() || check_revoke.is_some())
+}
+
 /// Configure a libcurl http handle with the defaults options for Cargo
 pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<()> {
     // The timeout option for libcurl by default times out the entire transfer,
@@ -329,7 +338,7 @@ fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
 /// * `HTTP_PROXY` env var
 /// * `https_proxy` env var
 /// * `HTTPS_PROXY` env var
-pub fn http_proxy_exists(config: &Config) -> CargoResult<bool> {
+fn http_proxy_exists(config: &Config) -> CargoResult<bool> {
     if http_proxy(config)?.is_some() {
         Ok(true)
     } else {
@@ -338,7 +347,7 @@ pub fn http_proxy_exists(config: &Config) -> CargoResult<bool> {
     }
 }
 
-pub fn http_timeout(config: &Config) -> CargoResult<Option<i64>> {
+fn http_timeout(config: &Config) -> CargoResult<Option<i64>> {
     if let Some(s) = config.get_i64("http.timeout")? {
         return Ok(Some(s.val))
     }