Skip to content

Commit a697cc6

Browse files
committed
Downloading the binaries through a proxy if either HTTPS_PROXY or HTTP_PROXY environment variable is set.
closes rust-bitcoin#48
1 parent fed768c commit a697cc6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

build.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,19 @@ mod download {
114114
);
115115
println!("url:{}", url);
116116
let mut downloaded_bytes = Vec::new();
117-
let resp = ureq::get(&url).call().unwrap();
118-
assert_eq!(resp.status(), 200, "url {} didn't return 200", url);
119117

120-
let _size = resp
118+
let http_proxy = std::env::var("HTTPS_PROXY").or_else(|_| std::env::var("HTTP_PROXY"));
119+
let agent = if let Ok(proxy) = http_proxy {
120+
let proxy = ureq::Proxy::new(proxy).unwrap();
121+
ureq::AgentBuilder::new().proxy(proxy).build()
122+
} else {
123+
ureq::AgentBuilder::new().build()
124+
};
125+
126+
let _size = agent
127+
.get(&url)
128+
.call()
129+
.unwrap()
121130
.into_reader()
122131
.read_to_end(&mut downloaded_bytes)
123132
.unwrap();

0 commit comments

Comments
 (0)