Reconfigure curl handles after reset
authorAlex Crichton <alex@alexcrichton.com>
Tue, 5 Dec 2017 15:27:04 +0000 (07:27 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 5 Dec 2017 15:27:04 +0000 (07:27 -0800)
This'll ensure that all our proxy/speed data/etc will be preserved in the
libcurl configuration

Closes #4779

src/cargo/ops/mod.rs
src/cargo/ops/registry.rs
src/cargo/sources/registry/remote.rs
src/cargo/util/config.rs

index 0cd1ec718e0952c7a00e5e8ee03a62c36e9bfc5b..fa155b3f6a6f6d32a250a64fecb1fab320d31a23 100644 (file)
@@ -19,6 +19,7 @@ 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::{modify_owners, yank, OwnersOptions, PublishOpts};
+pub use self::registry::configure_http_handle;
 pub use self::cargo_fetch::fetch;
 pub use self::cargo_pkgid::pkgid;
 pub use self::resolve::{resolve_ws, resolve_ws_precisely, resolve_with_previous};
index 18f2d5cea6a948138c51b81ee9a1b9dcc46e6bf2..c6fc6e1208ca8cbaaa390bc145f94eca9cd7cc24 100644 (file)
@@ -273,6 +273,16 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
     // connect phase as well as a "low speed" timeout so if we don't receive
     // many bytes in a large-ish period of time then we time out.
     let mut handle = Easy::new();
+    configure_http_handle(config, &mut handle)?;
+    Ok(handle)
+}
+
+/// 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,
+    // but we probably don't want this. Instead we only set timeouts for the
+    // connect phase as well as a "low speed" timeout so if we don't receive
+    // many bytes in a large-ish period of time then we time out.
     handle.connect_timeout(Duration::new(30, 0))?;
     handle.low_speed_limit(10 /* bytes per second */)?;
     handle.low_speed_time(Duration::new(30, 0))?;
@@ -290,7 +300,7 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
         handle.connect_timeout(Duration::new(timeout as u64, 0))?;
         handle.low_speed_time(Duration::new(timeout as u64, 0))?;
     }
-    Ok(handle)
+    Ok(())
 }
 
 /// Find an explicit HTTP proxy if one is available.
index e40b35034ba4706266fe9ac5e19c9eedd5fcc327..9546bdb58a5959c12f2d001276e9a732ed3ef5fe 100644 (file)
@@ -10,7 +10,6 @@ use hex::ToHex;
 use serde_json;
 
 use core::{PackageId, SourceId};
-use ops;
 use sources::git;
 use sources::registry::{RegistryData, RegistryConfig, INDEX_LOCK};
 use util::network;
@@ -159,7 +158,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
         //
         // This way if there's a problem the error gets printed before we even
         // hit the index, which may not actually read this configuration.
-        ops::http_handle(self.config)?;
+        self.config.http()?;
 
         self.repo()?;
         self.head.set(None);
index f343a6cf7f6226e5d8b62b98e3d2568e62ec205c..fb2e4cb050d464cbdbf4e05df833b5db1bd15512 100644 (file)
@@ -633,7 +633,11 @@ impl Config {
         let http = self.easy.get_or_try_init(|| {
             ops::http_handle(self).map(RefCell::new)
         })?;
-        http.borrow_mut().reset();
+        {
+            let mut http = http.borrow_mut();
+            http.reset();
+            ops::configure_http_handle(self, &mut http)?;
+        }
         Ok(http)
     }
 }