Skip to content

Commit 61df5c9

Browse files
committed
Small tweaks & extract method
1 parent ca55953 commit 61df5c9

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

lychee-lib/src/client.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub struct ClientBuilder {
278278
/// Requests run through this chain where each item in the chain
279279
/// can modify the request. A chained item can also decide to exit
280280
/// early and return a status, so that subsequent chain items are
281-
/// skipped and no HTTP request is ever made.
281+
/// skipped and the lychee-internal request chain is not activated.
282282
plugin_request_chain: RequestChain,
283283
}
284284

@@ -486,7 +486,7 @@ impl Client {
486486
return Ok(Response::new(uri.clone(), Status::Excluded, source));
487487
}
488488

489-
let request_chain: RequestChain = Chain::new(vec![
489+
let chain: RequestChain = Chain::new(vec![
490490
Box::<Quirks>::default(),
491491
Box::new(credentials),
492492
Box::new(Checker::new(
@@ -500,7 +500,7 @@ impl Client {
500500
let status = match uri.scheme() {
501501
_ if uri.is_file() => self.check_file(uri).await,
502502
_ if uri.is_mail() => self.check_mail(uri).await,
503-
_ => self.check_website(uri, request_chain).await?,
503+
_ => self.check_website(uri, chain).await?,
504504
};
505505

506506
Ok(Response::new(uri.clone(), status, source))
@@ -533,11 +533,11 @@ impl Client {
533533
/// - The request failed.
534534
/// - The response status code is not accepted.
535535
/// - The URI cannot be converted to HTTPS.
536-
pub async fn check_website(&self, uri: &Uri, request_chain: RequestChain) -> Result<Status> {
537-
match self.check_website_inner(uri, &request_chain).await {
536+
pub async fn check_website(&self, uri: &Uri, chain: RequestChain) -> Result<Status> {
537+
match self.check_website_inner(uri, &chain).await {
538538
Status::Ok(code) if self.require_https && uri.scheme() == "http" => {
539539
if self
540-
.check_website_inner(&uri.to_https()?, &request_chain)
540+
.check_website_inner(&uri.to_https()?, &chain)
541541
.await
542542
.is_success()
543543
{
@@ -562,7 +562,7 @@ impl Client {
562562
/// - The URI is invalid.
563563
/// - The request failed.
564564
/// - The response status code is not accepted.
565-
pub async fn check_website_inner(&self, uri: &Uri, request_chain: &RequestChain) -> Status {
565+
pub async fn check_website_inner(&self, uri: &Uri, chain: &RequestChain) -> Status {
566566
// Workaround for upstream reqwest panic
567567
if validate_url(&uri.url) {
568568
if matches!(uri.scheme(), "http" | "https") {
@@ -587,16 +587,21 @@ impl Client {
587587
Err(e) => return e.into(),
588588
};
589589

590-
let chain = ClientRequestChain::new(vec![&self.plugin_request_chain, request_chain]);
591-
let status = chain.traverse(request).await;
590+
let status = ClientRequestChain::new(vec![&self.plugin_request_chain, chain])
591+
.traverse(request)
592+
.await;
593+
594+
self.handle_github(status, uri).await
595+
}
592596

597+
// Pull out the heavy machinery in case of a failed normal request.
598+
// This could be a GitHub URL and we ran into the rate limiter.
599+
// TODO: We should first try to parse the URI as GitHub URI first (Lucius, Jan 2023)
600+
async fn handle_github(&self, status: Status, uri: &Uri) -> Status {
593601
if status.is_success() {
594602
return status;
595603
}
596604

597-
// Pull out the heavy machinery in case of a failed normal request.
598-
// This could be a GitHub URL and we ran into the rate limiter.
599-
// TODO: We should first try to parse the URI as GitHub URI first (Lucius, Jan 2023)
600605
if let Ok(github_uri) = GithubUri::try_from(uri) {
601606
let status = self.check_github(github_uri).await;
602607
// Only return Github status in case of success

0 commit comments

Comments
 (0)