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
58 value_name,58 value_name,
59 ..59 ..
60 } = git_config::parse::key(key).expect("valid key statically known");60 } = git_config::parse::key(key).expect("valid key statically known");
61 let integer = config61 let integer = check_lenient(
62 .integer_filter(section_name, None, value_name, &mut filter)62 config
63 .transpose()63 .integer_filter(section_name, None, value_name, &mut filter)
64 .map_err(|err| crate::config::transport::Error::ConfigValue {64 .transpose()
65 source: err,65 .map_err(|err| crate::config::transport::Error::ConfigValue { source: err, key }),
66 key: "http.lowSpeedTime",66 lenient,
67 })?67 )?
68 .unwrap_or_default();68 .unwrap_or_default();
69 check_lenient_default(69 check_lenient_default(
70 integer70 integer
71 .try_into()71 .try_into()
@@ -78,6 +78,42 @@ impl crate::Repository { · 6 unmodified lines
78 || default,78 || default,
79 )79 )
80 }80 }
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 }
81 let mut opts = http::Options::default();117 let mut opts = http::Options::default();
82 let config = &self.config.resolved;118 let config = &self.config.resolved;
83 let mut trusted_only = self.filter_config_section();119 let mut trusted_only = self.filter_config_section();
@@ -140,6 +176,9 @@ impl crate::Repository { · 56 unmodified lines
140 proxy176 proxy
141 }177 }
142 });178 });
179 opts.connect_timeout =
180 integer_opt(config, lenient, "gitoxide.http.connectTimeout", "u64", trusted_only)?
181 .map(std::time::Duration::from_millis);
143 opts.user_agent = config182 opts.user_agent = config
144 .string_filter("http", None, "userAgent", &mut trusted_only)183 .string_filter("http", None, "userAgent", &mut trusted_only)
145 .and_then(|v| try_cow_to_string(v, lenient, "http.userAgent").transpose())184 .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 @@
1version https://git-lfs.github.com/spec/v11version https://git-lfs.github.com/spec/v1
2oid sha256:f569fc9c7f3412204be5f187eabecfe767cb9dc4528675ce4fcf539c6f02b8752oid sha256:c75c9f7d9f687dc688ba9d86fed546d98da793ee84d43a52d002d6ba2d79d082
3size 99203size 9940
git-repository/tests/fixtures/make_config_repos.sh+1−0
@@ -13,6 +13,7 @@ git init http-config · 12 unmodified lines
13 git config http.proxy http://localhost:909013 git config http.proxy http://localhost:9090
14 git config http.proxyAuthMethod anyauth14 git config http.proxyAuthMethod anyauth
15 git config http.userAgent agentJustForHttp15 git config http.userAgent agentJustForHttp
16 git config gitoxide.http.connectTimeout 60k
16)17)
17 18
18git init http-proxy-empty19git init http-proxy-empty
git-repository/tests/repository/config/transport_options.rs+1−5
@@ -50,11 +50,7 @@ mod http { · 49 unmodified lines
50 "TODO: implement auth"50 "TODO: implement auth"
51 );51 );
52 assert_eq!(user_agent.as_deref(), Some("agentJustForHttp"));52 assert_eq!(user_agent.as_deref(), Some("agentJustForHttp"));
53 assert_eq!(53 assert_eq!(connect_timeout, Some(std::time::Duration::from_millis(60 * 1024)));
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 );
58 assert!(54 assert!(
59 backend.is_none(),55 backend.is_none(),
60 "backed is never set as it's backend specific, rather custom options typically"56 "backed is never set as it's backend specific, rather custom options typically"