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

Allow setting low speed timeouts via Configurable #316

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ pub trait Configurable: request::WithRequestConfig {
})
}

/// Specify a maximum amount of time where transfer rate can go below
/// a minimum speed limit. `low_speed` is that limit in bytes/s.
///
/// If not set, no low speed limits are imposed.
fn low_speed_timeout(self, low_speed: u32, timeout: Duration) -> Self {
self.with_config(move |config| {
config.low_speed_timeout = Some((low_speed, timeout));
})
}

/// Configure how the use of HTTP versions should be negotiated with the
/// server.
///
Expand Down
6 changes: 6 additions & 0 deletions src/config/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ define_request_config! {
// Used by curl
timeout: Option<Duration>,
connect_timeout: Option<Duration>,
low_speed_timeout: Option<(u32, Duration)>,
version_negotiation: Option<VersionNegotiation>,
automatic_decompression: Option<bool>,
authentication: Option<Authentication>,
Expand Down Expand Up @@ -98,6 +99,11 @@ impl SetOpt for RequestConfig {
easy.timeout(timeout)?;
}

if let Some((low_speed, timeout)) = self.low_speed_timeout {
easy.low_speed_limit(low_speed)?;
easy.low_speed_time(timeout)?;
}

if let Some(timeout) = self.connect_timeout {
easy.connect_timeout(timeout)?;
}
Expand Down