Fix system HTTP proxy to send proxy-authorization (#1021)

Previously, HTTP proxies loaded from the system settings were not
respected for non-HTTPS requests. Now the PROXY_AUTHORIZATION header is
supplied on HTTP requests with a system proxy.
This commit is contained in:
Zicklag
2020-11-24 12:34:38 -06:00
committed by GitHub
parent e7be3eda04
commit 3cd9c29b30
2 changed files with 195 additions and 6 deletions

View File

@@ -94,6 +94,48 @@ async fn http_proxy_basic_auth_parsed() {
assert_eq!(res.status(), reqwest::StatusCode::OK);
}
#[tokio::test]
async fn system_http_proxy_basic_auth_parsed() {
let url = "http://hyper.rs/prox";
let server = server::http(move |req| {
assert_eq!(req.method(), "GET");
assert_eq!(req.uri(), url);
assert_eq!(req.headers()["host"], "hyper.rs");
assert_eq!(
req.headers()["proxy-authorization"],
"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
);
async { http::Response::default() }
});
// save system setting first.
let system_proxy = env::var("http_proxy");
// set-up http proxy.
env::set_var(
"http_proxy",
format!("http://Aladdin:open sesame@{}", server.addr()),
);
let res = reqwest::Client::builder()
.build()
.unwrap()
.get(url)
.send()
.await
.unwrap();
assert_eq!(res.url().as_str(), url);
assert_eq!(res.status(), reqwest::StatusCode::OK);
// reset user setting.
match system_proxy {
Err(_) => env::remove_var("http_proxy"),
Ok(proxy) => env::set_var("http_proxy", proxy),
}
}
#[tokio::test]
async fn test_no_proxy() {
let server = server::http(move |req| {