Disable tcp_nodelay for reqwest::Client and add rate limiting for https requests (#458)

This commit is contained in:
Jiahao XU 2022-10-07 15:51:34 +11:00 committed by GitHub
parent 8398ec2d4b
commit 76bc030f90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 243 additions and 99 deletions

View file

@ -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(())
})