From b1026fb9bb2b466921897fb8873035b9f5925212 Mon Sep 17 00:00:00 2001 From: lollerfirst <43107113+lollerfirst@users.noreply.github.com> Date: Tue, 9 Sep 2025 11:40:38 +0200 Subject: [PATCH] fix: None `host_matcher` applies the proxy to all hosts (#1054) * fix: None `host_matcher` applies the proxy to all hosts --- .../src/wallet/mint_connector/transport.rs | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/crates/cdk/src/wallet/mint_connector/transport.rs b/crates/cdk/src/wallet/mint_connector/transport.rs index abd3b55e..5a481290 100644 --- a/crates/cdk/src/wallet/mint_connector/transport.rs +++ b/crates/cdk/src/wallet/mint_connector/transport.rs @@ -78,29 +78,27 @@ impl Transport for Async { host_matcher: Option<&str>, accept_invalid_certs: bool, ) -> Result<(), Error> { - let regex = host_matcher - .map(regex::Regex::new) - .transpose() - .map_err(|e| Error::Custom(e.to_string()))?; - self.inner = reqwest::Client::builder() - .proxy(reqwest::Proxy::custom(move |url| { - if let Some(matcher) = regex.as_ref() { - if let Some(host) = url.host_str() { - if matcher.is_match(host) { - return Some(proxy.clone()); - } - } - } - None - })) - .danger_accept_invalid_certs(accept_invalid_certs) // Allow self-signed certs + let builder = reqwest::Client::builder().danger_accept_invalid_certs(accept_invalid_certs); + + let builder = match host_matcher { + Some(pattern) => { + // When a matcher is provided, only apply the proxy to matched hosts + let regex = regex::Regex::new(pattern).map_err(|e| Error::Custom(e.to_string()))?; + builder.proxy(reqwest::Proxy::custom(move |url| { + url.host_str() + .filter(|host| regex.is_match(host)) + .map(|_| proxy.clone()) + })) + } + // Apply proxy to all requests when no matcher is provided + None => { + builder.proxy(reqwest::Proxy::all(proxy).map_err(|e| Error::Custom(e.to_string()))?) + } + }; + + self.inner = builder .build() - .map_err(|e| { - Error::HttpError( - e.status().map(|status_code| status_code.as_u16()), - e.to_string(), - ) - })?; + .map_err(|e| Error::HttpError(e.status().map(|s| s.as_u16()), e.to_string()))?; Ok(()) }