diff --git a/Cargo.toml b/Cargo.toml index dfc57f97..1fa5f2c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ tempfile = "3" base64 = "0.10" derive_builder = "0.7.1" which = "2.0" -reqwest = { version = "0.9", optional = true } +ureq = { version = "0.9", optional = true } directories = { version = "1.0", optional = true } zip = { version = "0.5", optional = true } @@ -43,5 +43,5 @@ path = "src/lib.rs" [features] default = [ "fetch" ] -fetch = [ "reqwest", "directories", "zip" ] +fetch = [ "ureq", "directories", "zip" ] nightly = [] diff --git a/src/browser/fetcher.rs b/src/browser/fetcher.rs index 9dafa04a..2e9c0f5c 100644 --- a/src/browser/fetcher.rs +++ b/src/browser/fetcher.rs @@ -1,7 +1,7 @@ use directories::ProjectDirs; use failure::{format_err, Error}; use log::*; -use reqwest::{self, header::CONTENT_LENGTH}; +use ureq; use zip; use std::{ @@ -104,14 +104,14 @@ impl<'a> Fetcher<'a> { let url = dl_url(self.rev)?; info!("Chrome download url: {}", url); let total = get_size(&url)?; - info!("Total size of download: {}", total); + info!("Total size of download: {} MiB", total); let path = self.base_path(self.rev).with_extension("zip"); info!("Creating file for download: {}", &path.display()); let mut file = OpenOptions::new().create(true).write(true).open(&path)?; - let mut resp = reqwest::get(&url)?; - io::copy(&mut resp, &mut file)?; + let resp = ureq::get(&url).call(); + io::copy(&mut resp.into_reader(), &mut file)?; self.unzip(&path)?; @@ -123,7 +123,10 @@ impl<'a> Fetcher<'a> { let extract_path = self.base_path(self.rev); fs::create_dir_all(&extract_path)?; - info!("Extracting: {}", extract_path.display()); + info!( + "Extracting (this can take a while): {}", + extract_path.display() + ); for i in 0..archive.len() { let mut file = archive.by_index(i)?; @@ -179,13 +182,9 @@ impl<'a> Fetcher<'a> { } fn get_size>(url: U) -> Result { - let client = reqwest::Client::new(); - let response = client.head(url.as_ref()).send()?; - match response.headers().get(CONTENT_LENGTH) { - Some(len) => { - let length = u64::from_str(len.to_str()?)?; - Ok(length) - } + let resp = ureq::get(url.as_ref()).call(); + match resp.header("Content-Length") { + Some(len) => Ok(u64::from_str(len)? / 2_u64.pow(20)), None => Err(format_err!("response doesn't include the content length")), } }