add argument to specify proxy credentials (#278)
This commit is contained in:
parent
a2b3f18d76
commit
7635e5ca10
2 changed files with 11 additions and 1 deletions
|
@ -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."
|
||||
)]
|
||||
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)]
|
||||
|
|
|
@ -221,7 +221,11 @@ fn run(args: commands::Args) -> anyhow::Result<()> {
|
|||
|
||||
let mut http_client = reqwest::blocking::Client::builder();
|
||||
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);
|
||||
}
|
||||
let http_client = http_client.build()?;
|
||||
|
|
Loading…
Reference in a new issue