https support with http fallback

This commit is contained in:
delorean 2024-05-23 15:14:51 -05:00
parent eff932c415
commit 072f882490
3 changed files with 18 additions and 5 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/target
TODO
/staging

View File

@ -33,11 +33,11 @@ pub fn parsehit(sc: u16, url: String, title: String) -> String {
format!(
"{} {} {} {}{}{}",
fmtcode(sc),
"|".black().bold(),
"|".bright_black().bold(),
url.white().underline(),
"[".black().bold(),
"[".bright_black().bold(),
parsetitle(title).bright_cyan().bold(),
"]".black().bold()
"]".bright_black().bold()
)
}
@ -46,6 +46,6 @@ pub fn banner() {
"{}{} {}",
"speed".bright_cyan().bold(),
"boat".bright_magenta().bold(),
VERSION.black()
VERSION.bright_black()
);
}

View File

@ -19,13 +19,24 @@ pub fn mkclient(redir: bool) -> Result<Client, reqwest::Error> {
.build()
}
async fn sendreq(c: &Client, use_https: bool, url: &str) -> Result<reqwest::Response, reqwest::Error> {
let dest: String = if use_https { format!("https://{url}/") } else { format!("http://{url}/") };
c.get(dest).send().await
}
pub async fn query(
c: Client,
url: &str,
codes: Vec<u16>,
exclude: bool,
) -> Result<(), reqwest::Error> {
let response = c.get(format!("http://{url}/")).send().await?;
let response: reqwest::Response;
if let Ok(res) = sendreq(&c, true, url).await {
response = res;
} else {
response = sendreq(&c, false, url).await?;
}
let statcode = response.status().as_u16();
if codes.len() > 0 {