Skip to content

Commit

Permalink
extra-headers respects empty entries to clear the list
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 11, 2022
1 parent ef64395 commit 9707f7f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
18 changes: 12 additions & 6 deletions git-repository/src/repository/config/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ impl crate::Repository {
let mut opts = http::Options::default();
let config = &self.config.resolved;
let mut trusted_only = self.filter_config_section();
opts.extra_headers = config
.strings_filter("http", None, "extraHeader", &mut trusted_only)
.unwrap_or_default()
.into_iter()
.filter_map(try_cow_to_string)
.collect();
opts.extra_headers = {
let mut headers: Vec<_> = config
.strings_filter("http", None, "extraHeader", &mut trusted_only)
.unwrap_or_default()
.into_iter()
.filter_map(try_cow_to_string)
.collect();
if let Some(empty_pos) = headers.iter().rev().position(|h| h.is_empty()) {
headers.drain(..headers.len() - empty_pos);
}
headers
};

if let Some(follow_redirects) = config.string_filter("http", None, "followRedirects", &mut trusted_only)
{
Expand Down
2 changes: 2 additions & 0 deletions git-repository/tests/fixtures/make_fetch_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ git clone --shared base worktree-root
git init http-config
(cd http-config
git config http.extraHeader "ExtraHeader: value1"
git config --add http.extraHeader ""
git config --add http.extraHeader "ExtraHeader: value2"
git config --add http.extraHeader "ExtraHeader: value3"
git config http.followRedirects initial
git config http.lowSpeedLimit 5k
git config http.lowSpeedTime 10
Expand Down
6 changes: 5 additions & 1 deletion git-repository/tests/repository/config/transport_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ mod http {
} = http_config
.downcast_ref::<git_transport::client::http::Options>()
.expect("http options have been created");
assert_eq!(extra_headers, &["ExtraHeader: value1", "ExtraHeader: value2"]);
assert_eq!(
extra_headers,
&["ExtraHeader: value2", "ExtraHeader: value3"],
"it respects empty values to clear prior values"
);
assert_eq!(
*follow_redirects,
git_transport::client::http::options::FollowRedirects::Initial
Expand Down

0 comments on commit 9707f7f

Please sign in to comment.