From f3cabddd0dc2e7175a446095b4a7bf68f962460d Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Thu, 22 Nov 2018 15:09:54 +0000 Subject: [PATCH] Add (back) support for proxies (#68) Fixes #65 --- src/cache.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index 72436ba..5f1359e 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; #[cfg(unix)] use std::os::unix::fs::MetadataExt; -use reqwest; +use reqwest::{Client, Proxy}; use flate2::read::GzDecoder; use tar::Archive; use time; @@ -61,7 +61,19 @@ impl Cache { /// Download the archive fn download(&self) -> Result, TealdeerError> { - let mut resp = reqwest::get(&self.url)?; + let mut builder = Client::builder(); + if let Ok(ref host) = env::var("HTTP_PROXY") { + if let Ok(proxy) = Proxy::http(host) { + builder = builder.proxy(proxy); + } + } + if let Ok(ref host) = env::var("HTTPS_PROXY") { + if let Ok(proxy) = Proxy::https(host) { + builder = builder.proxy(proxy); + } + } + let client = builder.build().unwrap_or_else(|_| Client::new()); + let mut resp = client.get(&self.url).send()?; let mut buf: Vec = vec![]; let bytes_downloaded = resp.copy_to(&mut buf)?; debug!("{} bytes downloaded", bytes_downloaded);