mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-17 05:00:26 +00:00
Extract function and add SAFETY note
This commit is contained in:
parent
a3184190b8
commit
d5b9b84db6
1 changed files with 8 additions and 2 deletions
|
|
@ -37,7 +37,7 @@ 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;
|
||||
|
|
@ -45,7 +45,7 @@ impl Checker {
|
|||
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
|
||||
}
|
||||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue