Skip to content

Commit 7c4834d

Browse files
committed
Extract function and add SAFETY note
1 parent 61df5c9 commit 7c4834d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lychee-lib/src/checker.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ impl Checker {
3737
let mut retries: u64 = 0;
3838
let mut wait_time = self.retry_wait_time;
3939

40-
let mut status = self.check_default(request.try_clone().unwrap()).await; // TODO: try_clone
40+
let mut status = self.check_default(clone_unwrap(&request)).await;
4141
while retries < self.max_retries {
4242
if status.is_success() || !status.should_retry() {
4343
return status;
4444
}
4545
retries += 1;
4646
tokio::time::sleep(wait_time).await;
4747
wait_time = wait_time.saturating_mul(2);
48-
status = self.check_default(request.try_clone().unwrap()).await; // TODO: try_clone
48+
status = self.check_default(clone_unwrap(&request)).await;
4949
}
5050
status
5151
}
@@ -59,6 +59,12 @@ impl Checker {
5959
}
6060
}
6161

62+
/// SAFETY: unwrapping the `try_clone` of `reqwest::Request` is safe because a request only fails to be cloned when `body` of `Request` is a stream
63+
/// and `body` cannot be a stream as long as the `stream` feature is disabled.
64+
fn clone_unwrap(request: &Request) -> Request {
65+
request.try_clone().unwrap()
66+
}
67+
6268
#[async_trait]
6369
impl Chainable<Request, Status> for Checker {
6470
async fn chain(&mut self, input: Request) -> ChainResult<Request, Status> {

0 commit comments

Comments
 (0)