Skip to content

Commit

Permalink
Allow setting low speed timeouts via Configurable
Browse files Browse the repository at this point in the history
 Expose libcurl's low speed timeout functionality by adding
 a `low_speed_timeout()` method to `Configurable`.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
  • Loading branch information
MoSal committed Mar 29, 2021
1 parent 2cd2f88 commit 1aced2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 1aced2b

Please sign in to comment.