Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl Client {
alternative_hosts: Vec<String>,
account_id: AccountId,
user_agent: &str,
network_interface: Option<&str>,
#[cfg(not(target_os = "windows"))] network_interface: Option<&str>,
#[cfg(target_os = "windows")] network_interface: Option<std::net::IpAddr>,
Comment on lines +54 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A function argument changing type is pretty nasty. But defining a trait seems like overkill. The other option is moving this to a method but I get that we want to strongly encourage callers to set it. I think this is fine for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it does not look great, but it's the only solution I can think of that forces the caller to use this correctly. I don't see how a trait would even work for this.

resolver_fallback_cache: Option<Arc<dyn ResolverFallbackCache>>,
) -> anyhow::Result<Self> {
let mut base_url = base_url.to_string();
Expand Down Expand Up @@ -88,7 +89,8 @@ impl Client {
fn http_client_builder(
user_agent: &str,
rustls_config: rustls::ClientConfig,
network_interface: Option<&str>,
#[cfg(not(target_os = "windows"))] network_interface: Option<&str>,
#[cfg(target_os = "windows")] network_interface: Option<std::net::IpAddr>,
resolver_fallback_cache: Arc<GaiResolverWithFallback>,
) -> anyhow::Result<reqwest::Client> {
let builder = ClientBuilder::new()
Expand All @@ -99,7 +101,10 @@ impl Client {
.dns_resolver(resolver_fallback_cache);
let builder = match network_interface {
None => builder,
#[cfg(not(target_os = "windows"))]
Some(network_interface) => builder.interface(network_interface),
#[cfg(target_os = "windows")]
Some(network_interface) => builder.local_address(network_interface),
};
builder.build().context("failed to initialize HTTP client")
}
Expand Down