add argument to specify proxy credentials (#278)

This commit is contained in:
Carson McManus 2023-07-05 06:49:17 -04:00 committed by GitHub
parent a2b3f18d76
commit 7635e5ca10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -132,6 +132,12 @@ pub(crate) struct GlobalArgs {
long_help = "Use a proxy for HTTP requests. This is useful if you are behind a firewall and need to use a proxy to access the internet." long_help = "Use a proxy for HTTP requests. This is useful if you are behind a firewall and need to use a proxy to access the internet."
)] )]
pub http_proxy: Option<String>, pub http_proxy: Option<String>,
#[clap(
long,
help = "Credentials to use for proxy authentication in the format username:password."
)]
pub proxy_credentials: Option<String>,
} }
#[derive(Debug, Clone, Parser)] #[derive(Debug, Clone, Parser)]

View file

@ -221,7 +221,11 @@ fn run(args: commands::Args) -> anyhow::Result<()> {
let mut http_client = reqwest::blocking::Client::builder(); let mut http_client = reqwest::blocking::Client::builder();
if let Some(proxy) = &globalargs.http_proxy { if let Some(proxy) = &globalargs.http_proxy {
let proxy = reqwest::Proxy::all(proxy)?; let mut proxy = reqwest::Proxy::all(proxy)?;
if let Some(proxy_creds) = &globalargs.proxy_credentials {
let mut creds = proxy_creds.splitn(2, ':');
proxy = proxy.basic_auth(creds.next().unwrap(), creds.next().unwrap());
}
http_client = http_client.proxy(proxy); http_client = http_client.proxy(proxy);
} }
let http_client = http_client.build()?; let http_client = http_client.build()?;