mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-19 02:10:03 +00:00
Disable tcp_nodelay
for reqwest::Client
and add rate limiting for https requests (#458)
This commit is contained in:
parent
8398ec2d4b
commit
76bc030f90
12 changed files with 243 additions and 99 deletions
|
@ -4,7 +4,6 @@ use compact_str::{CompactString, ToCompactString};
|
|||
use futures_util::stream::{FuturesUnordered, StreamExt};
|
||||
use log::{debug, warn};
|
||||
use once_cell::sync::OnceCell;
|
||||
use reqwest::{Client, Method};
|
||||
use serde::Serialize;
|
||||
use strum::IntoEnumIterator;
|
||||
use tinytemplate::TinyTemplate;
|
||||
|
@ -14,7 +13,7 @@ use crate::{
|
|||
errors::BinstallError,
|
||||
helpers::{
|
||||
download::Download,
|
||||
remote::{get_redirected_final_url, remote_exists},
|
||||
remote::{Client, Method},
|
||||
tasks::AutoAbortJoinHandle,
|
||||
},
|
||||
manifests::cargo_toml_binstall::{PkgFmt, PkgMeta},
|
||||
|
@ -59,11 +58,9 @@ impl GhCrateMeta {
|
|||
AutoAbortJoinHandle::spawn(async move {
|
||||
debug!("Checking for package at: '{url}'");
|
||||
|
||||
Ok(
|
||||
(remote_exists(client.clone(), url.clone(), Method::HEAD).await?
|
||||
|| remote_exists(client, url.clone(), Method::GET).await?)
|
||||
.then_some((url, pkg_fmt)),
|
||||
)
|
||||
Ok((client.remote_exists(url.clone(), Method::HEAD).await?
|
||||
|| client.remote_exists(url.clone(), Method::GET).await?)
|
||||
.then_some((url, pkg_fmt)))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -81,7 +78,11 @@ impl super::Fetcher for GhCrateMeta {
|
|||
|
||||
async fn find(&self) -> Result<bool, BinstallError> {
|
||||
let repo = if let Some(repo) = self.data.repo.as_deref() {
|
||||
Some(get_redirected_final_url(&self.client, Url::parse(repo)?).await?)
|
||||
Some(
|
||||
self.client
|
||||
.get_redirected_final_url(Url::parse(repo)?)
|
||||
.await?,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
|
@ -2,14 +2,15 @@ use std::{path::Path, sync::Arc};
|
|||
|
||||
use compact_str::CompactString;
|
||||
use log::debug;
|
||||
use reqwest::Client;
|
||||
use reqwest::Method;
|
||||
use tokio::task::JoinHandle;
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
errors::BinstallError,
|
||||
helpers::{download::Download, remote::remote_exists},
|
||||
helpers::{
|
||||
download::Download,
|
||||
remote::{Client, Method},
|
||||
},
|
||||
manifests::cargo_toml_binstall::{PkgFmt, PkgMeta},
|
||||
};
|
||||
|
||||
|
@ -43,7 +44,9 @@ impl super::Fetcher for QuickInstall {
|
|||
let url = self.package_url();
|
||||
self.report();
|
||||
debug!("Checking for package at: '{url}'");
|
||||
remote_exists(self.client.clone(), Url::parse(&url)?, Method::HEAD).await
|
||||
self.client
|
||||
.remote_exists(Url::parse(&url)?, Method::HEAD)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError> {
|
||||
|
@ -112,15 +115,7 @@ impl QuickInstall {
|
|||
let url = Url::parse(&stats_url)?;
|
||||
debug!("Sending installation report to quickinstall ({url})");
|
||||
|
||||
client
|
||||
.request(Method::HEAD, url.clone())
|
||||
.send()
|
||||
.await
|
||||
.map_err(|err| BinstallError::Http {
|
||||
method: Method::HEAD,
|
||||
url,
|
||||
err,
|
||||
})?;
|
||||
client.remote_exists(url, Method::HEAD).await?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue