From 7635e5ca10209028f175ff8b7fa9cd2b9eab49cc Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Wed, 5 Jul 2023 06:49:17 -0400 Subject: [PATCH] add argument to specify proxy credentials (#278) --- src/commands.rs | 6 ++++++ src/main.rs | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/commands.rs b/src/commands.rs index bf0d9b7..1401b34 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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, + + #[clap( + long, + help = "Credentials to use for proxy authentication in the format username:password." + )] + pub proxy_credentials: Option, } #[derive(Debug, Clone, Parser)] diff --git a/src/main.rs b/src/main.rs index cbc624f..d7fe8ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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()?;