Skip to content

Commit c30ce34

Browse files
authored
Added support for HTTP proxy with hyper-proxy2 (#1496)
Signed-off-by: Aviram Hassan <[email protected]>
1 parent a6f4337 commit c30ce34

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

kube-client/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ jsonpatch = ["kube-core/jsonpatch"]
2525
admission = ["kube-core/admission"]
2626
config = ["__non_core", "pem", "home"]
2727
socks5 = ["hyper-socks2"]
28+
http_proxy = ["hyper-proxy2"]
2829
unstable-client = []
2930

3031
# private feature sets; do not use
3132
__non_core = ["tracing", "serde_yaml", "base64"]
3233

3334
[package.metadata.docs.rs]
34-
features = ["client", "rustls-tls", "openssl-tls", "ws", "oauth", "oidc", "jsonpatch", "admission", "k8s-openapi/latest", "socks5", "unstable-client"]
35+
features = ["client", "rustls-tls", "openssl-tls", "ws", "oauth", "oidc", "jsonpatch", "admission", "k8s-openapi/latest", "socks5", "unstable-client", "http-proxy"]
3536
# Define the configuration attribute `docsrs`. Used to enable `doc_cfg` feature.
3637
rustdoc-args = ["--cfg", "docsrs"]
3738

@@ -61,6 +62,7 @@ kube-core = { path = "../kube-core", version = "=0.91.0" }
6162
jsonpath-rust = { workspace = true, optional = true }
6263
tokio-util = { workspace = true, features = ["io", "codec"], optional = true }
6364
hyper = { workspace = true, features = ["client", "http1"], optional = true }
65+
hyper-proxy2 = {version = "0.1", optional = true}
6466
hyper-util = { workspace = true, features = ["client", "client-legacy", "http1", "tokio"], optional = true }
6567
hyper-rustls = { workspace = true, features = ["http1", "logging", "native-tokio", "ring", "tls12"], optional = true }
6668
hyper-socks2 = { workspace = true, optional = true }

kube-client/src/client/builder.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,28 @@ impl TryFrom<Config> for ClientBuilder<GenericService> {
8282
let mut connector = HttpConnector::new();
8383
connector.enforce_http(false);
8484

85-
#[cfg(feature = "socks5")]
86-
if let Some(proxy_addr) = config.proxy_url.clone() {
87-
let connector = hyper_socks2::SocksConnector {
88-
proxy_addr,
89-
auth: None,
90-
connector,
91-
};
92-
93-
return make_generic_builder(connector, config);
85+
match config.proxy_url.as_ref() {
86+
#[cfg(feature = "socks5")]
87+
Some(proxy_url) if proxy_url.scheme_str() == Some("socks5") => {
88+
let connector = hyper_socks2::SocksConnector {
89+
proxy_addr: proxy_url.clone(),
90+
auth: None,
91+
connector,
92+
};
93+
94+
make_generic_builder(connector, config)
95+
}
96+
97+
#[cfg(feature = "http-proxy")]
98+
Some(proxy_url) if proxy_url.scheme_str() == Some("http") => {
99+
let proxy = hyper_proxy2::Proxy::new(hyper_proxy2::Intercept::All, proxy_url.clone());
100+
let connector = hyper_proxy2::ProxyConnector::from_proxy_unsecured(connector, proxy);
101+
102+
make_generic_builder(connector, config)
103+
}
104+
105+
_ => make_generic_builder(connector, config),
94106
}
95-
96-
make_generic_builder(connector, config)
97107
}
98108
}
99109

kube/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ unstable-client = ["kube-client/unstable-client"]
3737
socks5 = ["kube-client/socks5"]
3838

3939
[package.metadata.docs.rs]
40-
features = ["client", "rustls-tls", "openssl-tls", "derive", "ws", "oauth", "jsonpatch", "admission", "runtime", "k8s-openapi/latest", "unstable-runtime", "socks5"]
40+
features = ["client", "rustls-tls", "openssl-tls", "derive", "ws", "oauth", "jsonpatch", "admission", "runtime", "k8s-openapi/latest", "unstable-runtime", "socks5", "http-proxy"]
4141
# Define the configuration attribute `docsrs`. Used to enable `doc_cfg` feature.
4242
rustdoc-args = ["--cfg", "docsrs"]
4343

0 commit comments

Comments
 (0)