From: Alex Crichton Date: Tue, 5 Dec 2017 15:27:04 +0000 (-0800) Subject: Reconfigure curl handles after reset X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~4^2~33^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5c6086847b39b691fd1e8b4a0f69df7cb342e784;p=cargo.git Reconfigure curl handles after reset This'll ensure that all our proxy/speed data/etc will be preserved in the libcurl configuration Closes #4779 --- diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index 0cd1ec718..fa155b3f6 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -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}; diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 18f2d5cea..c6fc6e120 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -273,6 +273,16 @@ pub fn http_handle(config: &Config) -> CargoResult { // 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 { 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. diff --git a/src/cargo/sources/registry/remote.rs b/src/cargo/sources/registry/remote.rs index e40b35034..9546bdb58 100644 --- a/src/cargo/sources/registry/remote.rs +++ b/src/cargo/sources/registry/remote.rs @@ -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); diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index f343a6cf7..fb2e4cb05 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -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) } }