Skip to content

Commit

Permalink
Avoid hardcoding some arbitrary default for connect timeouts, use cur…
Browse files Browse the repository at this point in the history
…l default instead like git

We also define a new gitoxide specific configuration option to allow
setting a connection timeout
  • Loading branch information
Byron committed Nov 15, 2022
1 parent f0625de commit 1766568
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
4 changes: 3 additions & 1 deletion git-transport/src/client/blocking_io/http/curl/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ pub fn new() -> (
}
handle.http_headers(headers)?;
handle.transfer_encoding(false)?;
handle.connect_timeout(connect_timeout)?;
if let Some(timeout) = connect_timeout {
handle.connect_timeout(timeout)?;
}
handle.tcp_keepalive(true)?;

if low_speed_time_seconds > 0 && low_speed_limit_bytes_per_second > 0 {
Expand Down
23 changes: 4 additions & 19 deletions git-transport/src/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,11 @@ pub mod options {
ProxyAuthMethod::AnyAuth
}
}

impl Default for super::Options {
fn default() -> Self {
super::Options {
extra_headers: vec![],
follow_redirects: Default::default(),
low_speed_limit_bytes_per_second: 0,
low_speed_time_seconds: 0,
proxy: None,
proxy_auth_method: None,
user_agent: None,
connect_timeout: std::time::Duration::from_secs(20),
backend: None,
}
}
}
}

/// Options to configure curl requests.
// TODO: testing most of these fields requires a lot of effort, unless special flags to introspect ongoing requests are added.
#[derive(Debug, Clone)]
#[derive(Default, Debug, Clone)]
pub struct Options {
/// Headers to be added to every request.
/// They are applied unconditionally and are expected to be valid as they occour in an HTTP request, like `header: value`, without newlines.
Expand Down Expand Up @@ -127,8 +111,9 @@ pub struct Options {
pub user_agent: Option<String>,
/// The amount of time we wait until aborting a connection attempt.
///
/// Defaults to 20s.
pub connect_timeout: std::time::Duration,
/// If `None`, this typically defaults to 2 minutes to 5 minutes.
/// Refers to `gitoxide.http.connectTimeout`.
pub connect_timeout: Option<std::time::Duration>,
/// Backend specific options, if available.
pub backend: Option<Arc<Mutex<dyn Any + Send + Sync + 'static>>>,
}
Expand Down

0 comments on commit 1766568

Please sign in to comment.