Selaa lähdekoodia

fix: None `host_matcher` applies the proxy to all hosts (#1054)

* fix: None `host_matcher` applies the proxy to all hosts
lollerfirst 1 kuukausi sitten
vanhempi
säilyke
b1026fb9bb
1 muutettua tiedostoa jossa 20 lisäystä ja 22 poistoa
  1. 20 22
      crates/cdk/src/wallet/mint_connector/transport.rs

+ 20 - 22
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(())
     }