Skip to content

Commit 1b14059

Browse files
committed
test: Ensure we can read proxy params from environment
Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy by directly calling env_proxy::for_url()
1 parent 9e3899b commit 1b14059

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

download/tests/read-proxy-env.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![cfg(feature = "reqwest-backend")]
2+
3+
use std::env::{remove_var, set_var};
4+
5+
use env_proxy::for_url;
6+
use url::Url;
7+
8+
fn scrub_env() {
9+
remove_var("http_proxy");
10+
remove_var("https_proxy");
11+
remove_var("HTTPS_PROXY");
12+
remove_var("ftp_proxy");
13+
remove_var("FTP_PROXY");
14+
remove_var("all_proxy");
15+
remove_var("ALL_PROXY");
16+
remove_var("no_proxy");
17+
remove_var("NO_PROXY");
18+
}
19+
20+
// Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy
21+
#[test]
22+
fn read_basic_proxy_params() {
23+
scrub_env();
24+
set_var("https_proxy", "http://proxy.example.com:8080");
25+
let u = Url::parse("https://www.example.org").ok().unwrap();
26+
assert_eq!(
27+
for_url(&u).host_port(),
28+
Some(("proxy.example.com".to_string(), 8080))
29+
);
30+
}

0 commit comments

Comments
 (0)