This commit is contained in:
sangge-redmi 2024-01-15 05:24:59 +08:00
parent 6095dc48fa
commit 207842c151

View File

@ -9,7 +9,6 @@ use std::io::Read;
use reqwest::header::{CONTENT_LENGTH, CONTENT_TYPE};
use std::fs::File;
use std::io::{self, Write};
use reqwest::blocking::Client;
@ -78,8 +77,11 @@ fn download(target: &str, quiet_mode: bool) -> Result<(), Box<dyn::std::error::E
.and_then(|ct_len| ct_len.to_str().ok())
.and_then(|ct_len_str| ct_len_str.parse::<u64>().ok());
let ct_type = resp.headers().get(CONTENT_TYPE)
.and_then(|ct_type| ct_type.to_str().ok());
let ct_type = headers.get(CONTENT_TYPE)
.and_then(|ct_type| ct_type.to_str().ok())
.unwrap_or("unknown"); // provide a default value
custom_print(format!("Type: {}", style(ct_type).green()), quiet_mode);
match ct_len {
Some(len) => {
@ -151,3 +153,10 @@ fn custom_print(message: String, quiet_mode: bool) {
}
}
fn parse_url(url: &str) -> Result<reqwest::Url, Box<dyn std::error::Error>> {
// Logic to parse and validate the URL
let parsed_url = reqwest::Url::parse(url)?;
Ok(parsed_url)
}