Skip to content

Commit

Permalink
Extract function and add SAFETY note
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-zahner committed Apr 11, 2024
1 parent 61df5c9 commit 7c4834d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lychee-lib/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ impl Checker {
let mut retries: u64 = 0;
let mut wait_time = self.retry_wait_time;

let mut status = self.check_default(request.try_clone().unwrap()).await; // TODO: try_clone
let mut status = self.check_default(clone_unwrap(&request)).await;
while retries < self.max_retries {
if status.is_success() || !status.should_retry() {
return status;
}
retries += 1;
tokio::time::sleep(wait_time).await;
wait_time = wait_time.saturating_mul(2);
status = self.check_default(request.try_clone().unwrap()).await; // TODO: try_clone
status = self.check_default(clone_unwrap(&request)).await;
}
status
}
Expand All @@ -59,6 +59,12 @@ impl Checker {
}
}

/// 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
/// and `body` cannot be a stream as long as the `stream` feature is disabled.
fn clone_unwrap(request: &Request) -> Request {
request.try_clone().unwrap()
}

#[async_trait]
impl Chainable<Request, Status> for Checker {
async fn chain(&mut self, input: Request) -> ChainResult<Request, Status> {
Expand Down

0 comments on commit 7c4834d

Please sign in to comment.