Skip to content

Commit fc1ff4f

Browse files
authored
fix(proxy): forward Proxy-Authorization header to HTTPS proxies for HTTP targets (#2872)
Closes #2870
1 parent b7c3712 commit fc1ff4f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/proxy.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::error::Error;
22
use std::fmt;
33
use std::sync::Arc;
44

5+
use http::uri::Scheme;
56
use http::{header::HeaderValue, HeaderMap, Uri};
67
use hyper_util::client::proxy::matcher;
78

@@ -452,12 +453,12 @@ impl Proxy {
452453
}
453454

454455
fn cache_maybe_has_http_auth(url: &Url, extra: &Option<HeaderValue>) -> bool {
455-
url.scheme() == "http"
456+
(url.scheme() == "http" || url.scheme() == "https")
456457
&& (url.username().len() > 0 || url.password().is_some() || extra.is_some())
457458
}
458459

459460
fn cache_maybe_has_http_custom_headers(url: &Url, extra: &Option<HeaderMap>) -> bool {
460-
url.scheme() == "http" && extra.is_some()
461+
(url.scheme() == "http" || url.scheme() == "https") && extra.is_some()
461462
}
462463

463464
impl fmt::Debug for Proxy {
@@ -551,7 +552,8 @@ impl Matcher {
551552

552553
pub(crate) fn http_non_tunnel_basic_auth(&self, dst: &Uri) -> Option<HeaderValue> {
553554
if let Some(proxy) = self.intercept(dst) {
554-
if proxy.uri().scheme_str() == Some("http") {
555+
let scheme = proxy.uri().scheme();
556+
if scheme == Some(&Scheme::HTTP) || scheme == Some(&Scheme::HTTPS) {
555557
return proxy.basic_auth().cloned();
556558
}
557559
}
@@ -565,7 +567,8 @@ impl Matcher {
565567

566568
pub(crate) fn http_non_tunnel_custom_headers(&self, dst: &Uri) -> Option<HeaderMap> {
567569
if let Some(proxy) = self.intercept(dst) {
568-
if proxy.uri().scheme_str() == Some("http") {
570+
let scheme = proxy.uri().scheme();
571+
if scheme == Some(&Scheme::HTTP) || scheme == Some(&Scheme::HTTPS) {
569572
return proxy.custom_headers().cloned();
570573
}
571574
}
@@ -912,7 +915,7 @@ mod tests {
912915
let m = Proxy::all("https://letme:in@yo.local")
913916
.unwrap()
914917
.into_matcher();
915-
assert!(!m.maybe_has_http_auth(), "https always tunnels");
918+
assert!(m.maybe_has_http_auth(), "https forwards");
916919

917920
let m = Proxy::all("http://letme:in@yo.local")
918921
.unwrap()

0 commit comments

Comments
 (0)