Skip to content

Commit 5b0ec83

Browse files
committed
feat: add HTTP proxy for client
This commit adds one more configuration for client about proxy, s.t. http_proxy. http_proxy sets the http proxy that the client uses to pull images, while no_proxy will define the remote address that will not be accessed by proxy. This is useful in a local registry scenario where original pull request is in http. Typical https_proxy looks like `http://127.0.0.1:5432` no_proxy looks like `127.0.0.1,192.168.1.1` Note that `client_builder.proxy()` function will add rather than overwrite the proxies to underlying reqwest::Client, thus no side effections upon the https proxy setting. Signed-off-by: Xynnn007 <[email protected]>
1 parent a8c91ab commit 5b0ec83

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: src/client.rs

+15
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ impl TryFrom<ClientConfig> for Client {
328328
client_builder = client_builder.proxy(proxy);
329329
}
330330

331+
if let Some(proxy_addr) = &config.http_proxy {
332+
let no_proxy = config
333+
.no_proxy
334+
.as_ref()
335+
.and_then(|no_proxy| NoProxy::from_string(no_proxy));
336+
let proxy = Proxy::http(proxy_addr)?.no_proxy(no_proxy);
337+
client_builder = client_builder.proxy(proxy);
338+
}
339+
331340
let default_token_expiration_secs = config.default_token_expiration_secs;
332341
Ok(Self {
333342
config: Arc::new(config),
@@ -1917,6 +1926,11 @@ pub struct ClientConfig {
19171926
/// This defaults to `None`.
19181927
pub https_proxy: Option<String>,
19191928

1929+
/// Set the `HTTP PROXY` used by the client.
1930+
///
1931+
/// This defaults to `None`.
1932+
pub http_proxy: Option<String>,
1933+
19201934
/// Set the `NO PROXY` used by the client.
19211935
///
19221936
/// This defaults to `None`.
@@ -1940,6 +1954,7 @@ impl Default for ClientConfig {
19401954
connect_timeout: None,
19411955
user_agent: DEFAULT_USER_AGENT,
19421956
https_proxy: None,
1957+
http_proxy: None,
19431958
no_proxy: None,
19441959
}
19451960
}

0 commit comments

Comments
 (0)