2024-10-31 18:16:42 -04:00
|
|
|
use reqwest::Url;
|
2024-09-29 17:45:53 -04:00
|
|
|
|
2024-10-31 19:56:08 -04:00
|
|
|
pub async fn download(url: &Url) -> Result<Vec<u8>, reqwest::Error> {
|
2024-10-31 23:11:26 -04:00
|
|
|
let mut client = reqwest::Client::builder();
|
|
|
|
|
|
|
|
#[cfg(not(target_family = "wasm"))]
|
|
|
|
{
|
|
|
|
client = client.no_proxy(); // This fixes localhost connections... for some reason (https://github.com/seanmonstar/reqwest/issues/913)
|
|
|
|
}
|
|
|
|
|
|
|
|
let client = client.build()?;
|
2024-10-30 16:27:32 -04:00
|
|
|
|
2024-10-31 18:16:42 -04:00
|
|
|
let body = client.get(url.to_string())
|
|
|
|
.send()
|
|
|
|
.await;
|
2024-09-29 17:45:53 -04:00
|
|
|
|
2024-10-31 19:56:08 -04:00
|
|
|
Ok(body?.bytes().await?.to_vec())
|
2024-09-29 17:45:53 -04:00
|
|
|
}
|