Skip to content

Commit

Permalink
Also read the connectTimeout in simple HTTP options
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 15, 2022
1 parent 2ab80e4 commit e055617
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
55 changes: 47 additions & 8 deletions git-repository/src/repository/config/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ impl crate::Repository {
value_name,
..
} = git_config::parse::key(key).expect("valid key statically known");
let integer = config
.integer_filter(section_name, None, value_name, &mut filter)
.transpose()
.map_err(|err| crate::config::transport::Error::ConfigValue {
source: err,
key: "http.lowSpeedTime",
})?
.unwrap_or_default();
let integer = check_lenient(
config
.integer_filter(section_name, None, value_name, &mut filter)
.transpose()
.map_err(|err| crate::config::transport::Error::ConfigValue { source: err, key }),
lenient,
)?
.unwrap_or_default();
check_lenient_default(
integer
.try_into()
Expand All @@ -78,6 +78,42 @@ impl crate::Repository {
|| default,
)
}
fn integer_opt<T>(
config: &git_config::File<'static>,
lenient: bool,
key: &'static str,
kind: &'static str,
mut filter: fn(&git_config::file::Metadata) -> bool,
) -> Result<Option<T>, crate::config::transport::Error>
where
T: TryFrom<i64>,
{
let git_config::parse::Key {
section_name,
subsection_name,
value_name,
} = git_config::parse::key(key).expect("valid key statically known");
check_lenient(
check_lenient(
config
.integer_filter(section_name, subsection_name, value_name, &mut filter)
.transpose()
.map_err(|err| crate::config::transport::Error::ConfigValue { source: err, key }),
lenient,
)?
.map(|integer| {
integer
.try_into()
.map_err(|_| crate::config::transport::Error::InvalidInteger {
actual: integer,
key,
kind,
})
})
.transpose(),
lenient,
)
}
let mut opts = http::Options::default();
let config = &self.config.resolved;
let mut trusted_only = self.filter_config_section();
Expand Down Expand Up @@ -140,6 +176,9 @@ impl crate::Repository {
proxy
}
});
opts.connect_timeout =
integer_opt(config, lenient, "gitoxide.http.connectTimeout", "u64", trusted_only)?
.map(std::time::Duration::from_millis);
opts.user_agent = config
.string_filter("http", None, "userAgent", &mut trusted_only)
.and_then(|v| try_cow_to_string(v, lenient, "http.userAgent").transpose())
Expand Down
Git LFS file not shown
1 change: 1 addition & 0 deletions git-repository/tests/fixtures/make_config_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ git init http-config
git config http.proxy http://localhost:9090
git config http.proxyAuthMethod anyauth
git config http.userAgent agentJustForHttp
git config gitoxide.http.connectTimeout 60k
)

git init http-proxy-empty
Expand Down
6 changes: 1 addition & 5 deletions git-repository/tests/repository/config/transport_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ mod http {
"TODO: implement auth"
);
assert_eq!(user_agent.as_deref(), Some("agentJustForHttp"));
assert_eq!(
connect_timeout,
std::time::Duration::from_secs(20),
"this is an arbitrary default, and it's her to allow adjustments of the default"
);
assert_eq!(connect_timeout, Some(std::time::Duration::from_millis(60 * 1024)));
assert!(
backend.is_none(),
"backed is never set as it's backend specific, rather custom options typically"
Expand Down

0 comments on commit e055617

Please sign in to comment.