From 50b044a100ca1fa4b4cd8ddc37b63d9bfbf140ac Mon Sep 17 00:00:00 2001 From: Jack Wampler Date: Tue, 18 Feb 2025 11:53:32 -0700 Subject: [PATCH] Support static routes for HTTP requests (#5487) allow static dns override --- common/http-api-client/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/http-api-client/src/lib.rs b/common/http-api-client/src/lib.rs index 312b00bec8..08c704897d 100644 --- a/common/http-api-client/src/lib.rs +++ b/common/http-api-client/src/lib.rs @@ -147,6 +147,8 @@ use thiserror::Error; use tracing::{instrument, warn}; use url::Url; +#[cfg(not(target_arch = "wasm32"))] +use std::net::SocketAddr; #[cfg(not(target_arch = "wasm32"))] use std::sync::Arc; @@ -292,6 +294,16 @@ impl ClientBuilder { self } + /// Override DNS resolution for specific domains to particular IP addresses. + /// + /// Set the port to `0` to use the conventional port for the given scheme (e.g. 80 for http). + /// Ports in the URL itself will always be used instead of the port in the overridden addr. + #[cfg(not(target_arch = "wasm32"))] + pub fn resolve_to_addrs(mut self, domain: &str, addrs: &[SocketAddr]) -> ClientBuilder { + self.reqwest_client_builder = self.reqwest_client_builder.resolve_to_addrs(domain, addrs); + self + } + /// Returns a Client that uses this ClientBuilder configuration. pub fn build(self) -> Result> where