Skip to content

Commit 86c9c51

Browse files
committed
Auto merge of #5957 - lostiniceland:5717-curl-low_speed, r=alexcrichton
Provide http-config option for curl low-speed-limit/time Fixes #5717 Provides new override options for curl in Cargo http config-section. ``` [http] timeout = 2 low-speed-limit = 5 ``` Test with the following during crate-download `sudo tc qdisc add dev eth0 handle 1: root htb default 11 && sudo tc class add dev eth0 parent 1: classid 1:1 htb rate 8bps && sudo tc class add dev eth0 parent 1:1 classid 1:11 htb rate 8bps` Clear with `sudo tc qdisc del dev eth0 root`
2 parents dd196e0 + d6cde29 commit 86c9c51

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/cargo/ops/registry.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
367367
// connect phase as well as a "low speed" timeout so if we don't receive
368368
// many bytes in a large-ish period of time then we time out.
369369
handle.connect_timeout(Duration::new(30, 0))?;
370-
handle.low_speed_limit(10 /* bytes per second */)?;
371-
handle.low_speed_time(Duration::new(30, 0))?;
370+
handle.low_speed_limit(http_low_speed_limit(config)?)?;
372371
if let Some(proxy) = http_proxy(config)? {
373372
handle.proxy(&proxy)?;
374373
}
@@ -390,6 +389,14 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
390389
Ok(())
391390
}
392391

392+
/// Find an override from config for curl low-speed-limit option, otherwise use default value
393+
fn http_low_speed_limit(config: &Config) -> CargoResult<u32> {
394+
if let Some(s) = config.get::<Option<u32>>("http.low-speed-limit")? {
395+
return Ok(s);
396+
}
397+
Ok(10)
398+
}
399+
393400
/// Find an explicit HTTP proxy if one is available.
394401
///
395402
/// Favor cargo's `http.proxy`, then git's `http.proxy`. Proxies specified

src/doc/src/reference/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ proxy = "host:port" # HTTP proxy to use for HTTP requests (defaults to none)
9595
timeout = 60000 # Timeout for each HTTP request, in milliseconds
9696
cainfo = "cert.pem" # Path to Certificate Authority (CA) bundle (optional)
9797
check-revoke = true # Indicates whether SSL certs are checked for revocation
98+
low-speed-limit = 0 # Lower threshold for bytes/sec (10 = default, 0 = disabled)
9899

99100
[build]
100101
jobs = 1 # number of parallel jobs, defaults to # of CPUs

0 commit comments

Comments
 (0)