History

Also read the connectTimeout in simple HTTP options

Sebastian Thiel committed 4 years ago

Commit e0556171 parent 2ab80e44 files · +51 −15Browse files

Unified · Split

4 files
  1. git-repository/src/repository/config/transport.rs +47 −8
  2. git-repository/tests/fixtures/generated-archives/make_config_repos.tar.xz +2 −2
  3. git-repository/tests/fixtures/make_config_repos.sh +1 −0
  4. git-repository/tests/repository/config/transport_options.rs +1 −5
git-repository/src/repository/config/transport.rs+47−8
@@ -58,14 +58,14 @@ impl crate::Repository { · 57 unmodified lines
5858 value_name,
5959 ..
6060 } = git_config::parse::key(key).expect("valid key statically known");
61− let integer = config
62− .integer_filter(section_name, None, value_name, &mut filter)
63− .transpose()
64− .map_err(|err| crate::config::transport::Error::ConfigValue {
65− source: err,
66− key: "http.lowSpeedTime",
67− })?
68− .unwrap_or_default();
61+ let integer = check_lenient(
62+ config
63+ .integer_filter(section_name, None, value_name, &mut filter)
64+ .transpose()
65+ .map_err(|err| crate::config::transport::Error::ConfigValue { source: err, key }),
66+ lenient,
67+ )?
68+ .unwrap_or_default();
6969 check_lenient_default(
7070 integer
7171 .try_into()
@@ -78,6 +78,42 @@ impl crate::Repository { · 6 unmodified lines
7878 || default,
7979 )
8080 }
81+ fn integer_opt<T>(
82+ config: &git_config::File<'static>,
83+ lenient: bool,
84+ key: &'static str,
85+ kind: &'static str,
86+ mut filter: fn(&git_config::file::Metadata) -> bool,
87+ ) -> Result<Option<T>, crate::config::transport::Error>
88+ where
89+ T: TryFrom<i64>,
90+ {
91+ let git_config::parse::Key {
92+ section_name,
93+ subsection_name,
94+ value_name,
95+ } = git_config::parse::key(key).expect("valid key statically known");
96+ check_lenient(
97+ check_lenient(
98+ config
99+ .integer_filter(section_name, subsection_name, value_name, &mut filter)
100+ .transpose()
101+ .map_err(|err| crate::config::transport::Error::ConfigValue { source: err, key }),
102+ lenient,
103+ )?
104+ .map(|integer| {
105+ integer
106+ .try_into()
107+ .map_err(|_| crate::config::transport::Error::InvalidInteger {
108+ actual: integer,
109+ key,
110+ kind,
111+ })
112+ })
113+ .transpose(),
114+ lenient,
115+ )
116+ }
81117 let mut opts = http::Options::default();
82118 let config = &self.config.resolved;
83119 let mut trusted_only = self.filter_config_section();
@@ -140,6 +176,9 @@ impl crate::Repository { · 56 unmodified lines
140176 proxy
141177 }
142178 });
179+ opts.connect_timeout =
180+ integer_opt(config, lenient, "gitoxide.http.connectTimeout", "u64", trusted_only)?
181+ .map(std::time::Duration::from_millis);
143182 opts.user_agent = config
144183 .string_filter("http", None, "userAgent", &mut trusted_only)
145184 .and_then(|v| try_cow_to_string(v, lenient, "http.userAgent").transpose())
git-repository/tests/fixtures/generated-archives/make_config_repos.tar.xz+2−2
@@ -1,3 +1,3 @@
11 version https://git-lfs.github.com/spec/v1
2−oid sha256:f569fc9c7f3412204be5f187eabecfe767cb9dc4528675ce4fcf539c6f02b875
3−size 9920
2+oid sha256:c75c9f7d9f687dc688ba9d86fed546d98da793ee84d43a52d002d6ba2d79d082
3+size 9940
git-repository/tests/fixtures/make_config_repos.sh+1−0
@@ -13,6 +13,7 @@ git init http-config · 12 unmodified lines
1313 git config http.proxy http://localhost:9090
1414 git config http.proxyAuthMethod anyauth
1515 git config http.userAgent agentJustForHttp
16+ git config gitoxide.http.connectTimeout 60k
1617 )
1718
1819 git init http-proxy-empty
git-repository/tests/repository/config/transport_options.rs+1−5
@@ -50,11 +50,7 @@ mod http { · 49 unmodified lines
5050 "TODO: implement auth"
5151 );
5252 assert_eq!(user_agent.as_deref(), Some("agentJustForHttp"));
53− assert_eq!(
54− connect_timeout,
55− std::time::Duration::from_secs(20),
56− "this is an arbitrary default, and it's her to allow adjustments of the default"
57− );
53+ assert_eq!(connect_timeout, Some(std::time::Duration::from_millis(60 * 1024)));
5854 assert!(
5955 backend.is_none(),
6056 "backed is never set as it's backend specific, rather custom options typically"