Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide http-config option for curl low-speed-limit/time #5957

Merged
merged 2 commits into from
Sep 3, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,12 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> 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.
handle.connect_timeout(Duration::new(30, 0))?;
handle.low_speed_limit(10 /* bytes per second */)?;
handle.low_speed_time(Duration::new(30, 0))?;
if let Some(config_low_speed_limit) = low_speed_limit(config)? {
handle.low_speed_limit(config_low_speed_limit)?;
}
if let Some(config_low_speed_time) = low_speed_time(config)? {
handle.low_speed_time(config_low_speed_time)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this conflicts with http_timeout below, but could it suffice to avoid configuring this manually and letting http_timeout below configure it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I just didn't notice the option was configured with the http-timeout.

}
if let Some(proxy) = http_proxy(config)? {
handle.proxy(&proxy)?;
}
Expand All @@ -390,6 +394,22 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
Ok(())
}

/// Find an override from config for curl low-speed-limit option, otherwise use default value
fn low_speed_limit(config: &Config) -> CargoResult<Option<u32>> {
if let Some(s) = config.get::<Option<u32>>("http.low-speed-limit")? {
return Ok(Some(s));
}
Ok(Some(10))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this always returns Some, perhaps this could return CargoResult<u32> and use .unwrap_or(10) internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the Option, but instead of unwrap_or I've set the default in the function. This way, everything is in one place.

}

/// Find an override from config for curl low-speed-time option, otherwise use default value
fn low_speed_time(config: &Config) -> CargoResult<Option<Duration>> {
if let Some(s) = config.get::<Option<u64>>("http.low-speed-time")? {
return Ok(Some(Duration::new(s, 0)));
}
Ok(Some(Duration::new(30, 0)))
}

/// Find an explicit HTTP proxy if one is available.
///
/// Favor cargo's `http.proxy`, then git's `http.proxy`. Proxies specified
Expand Down