Skip to content

Commit 1bc42e9

Browse files
committed
refactor
1 parent e642690 commit 1bc42e9

File tree

1 file changed

+17
-23
lines changed
  • gix-transport/src/client/blocking_io/http/reqwest

1 file changed

+17
-23
lines changed

gix-transport/src/client/blocking_io/http/reqwest/remote.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,30 @@ impl Default for Remote {
4242
let handle = std::thread::spawn(move || -> Result<(), Error> {
4343
let mut follow = None;
4444
let mut redirected_base_url = None::<String>;
45-
46-
// This initial value is just a place holder, it will get modified
47-
// before `client.execute` is called.
48-
let current_follow_policy = Arc::new(atomic::AtomicBool::new(false));
49-
50-
let follow_policy = Arc::clone(&current_follow_policy);
45+
let allow_redirects = Arc::new(atomic::AtomicBool::new(false));
5146

5247
// We may error while configuring, which is expected as part of the internal protocol. The error will be
5348
// received and the sender of the request might restart us.
5449
let client = reqwest::blocking::ClientBuilder::new()
5550
.connect_timeout(std::time::Duration::from_secs(20))
5651
.http1_title_case_headers()
57-
.redirect(reqwest::redirect::Policy::custom(move |attempt| {
58-
if follow_policy.load(atomic::Ordering::Relaxed) {
59-
let curr_url = attempt.url();
60-
let prev_urls = attempt.previous();
52+
.redirect(reqwest::redirect::Policy::custom({
53+
let allow_redirects = allow_redirects.clone();
54+
move |attempt| {
55+
if allow_redirects.load(atomic::Ordering::Relaxed) {
56+
let curr_url = attempt.url();
57+
let prev_urls = attempt.previous();
6158

62-
match prev_urls.first() {
63-
Some(prev_url) if prev_url.host_str() != curr_url.host_str() => {
64-
// gix does not want to be redirected to a different host.
65-
attempt.stop()
59+
match prev_urls.first() {
60+
Some(prev_url) if prev_url.host_str() != curr_url.host_str() => {
61+
// git does not want to be redirected to a different host.
62+
attempt.stop()
63+
}
64+
_ => attempt.follow(),
6665
}
67-
_ => attempt.follow(),
66+
} else {
67+
attempt.stop()
6868
}
69-
} else {
70-
attempt.stop()
7169
}
7270
}))
7371
.build()?;
@@ -121,12 +119,8 @@ impl Default for Remote {
121119
}
122120

123121
let follow = follow.get_or_insert(config.follow_redirects);
124-
125-
current_follow_policy.store(
126-
match *follow {
127-
FollowRedirects::None => false,
128-
FollowRedirects::Initial | FollowRedirects::All => true,
129-
},
122+
allow_redirects.store(
123+
matches!(follow, FollowRedirects::Initial | FollowRedirects::All),
130124
atomic::Ordering::Relaxed,
131125
);
132126

0 commit comments

Comments
 (0)