From 17665683efc8e25cbb35737a8c4132b98e5b6b7a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 15 Nov 2022 14:55:13 +0100 Subject: [PATCH] Avoid hardcoding some arbitrary default for connect timeouts, use curl default instead like git We also define a new gitoxide specific configuration option to allow setting a connection timeout --- .../client/blocking_io/http/curl/remote.rs | 4 +++- .../src/client/blocking_io/http/mod.rs | 23 ++++--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/git-transport/src/client/blocking_io/http/curl/remote.rs b/git-transport/src/client/blocking_io/http/curl/remote.rs index 9d1c08601de..9d671edfd74 100644 --- a/git-transport/src/client/blocking_io/http/curl/remote.rs +++ b/git-transport/src/client/blocking_io/http/curl/remote.rs @@ -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 { diff --git a/git-transport/src/client/blocking_io/http/mod.rs b/git-transport/src/client/blocking_io/http/mod.rs index 23b511a7d21..9474e74c62b 100644 --- a/git-transport/src/client/blocking_io/http/mod.rs +++ b/git-transport/src/client/blocking_io/http/mod.rs @@ -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. @@ -127,8 +111,9 @@ pub struct Options { pub user_agent: Option, /// 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, /// Backend specific options, if available. pub backend: Option>>, }