From 735c750f2ac1bf74cc194ca8ed0e8734ceb045f0 Mon Sep 17 00:00:00 2001 From: Jun Kurihara Date: Thu, 16 Nov 2023 12:17:08 +0900 Subject: [PATCH] chore: refactor --- legacy/Cargo.toml | 2 +- proxy-bin/Cargo.toml | 2 +- proxy-lib/src/http_client/http_client_main.rs | 8 +++++--- proxy-lib/src/lib.rs | 10 +--------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/legacy/Cargo.toml b/legacy/Cargo.toml index a39d3da..89f9a96 100644 --- a/legacy/Cargo.toml +++ b/legacy/Cargo.toml @@ -75,7 +75,7 @@ mimalloc = { version = "*", default-features = false } # logging tracing = { version = "0.1.40" } -tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } [dev-dependencies] trust-dns-client = "0.23.2" diff --git a/proxy-bin/Cargo.toml b/proxy-bin/Cargo.toml index 95e6434..1f29c88 100644 --- a/proxy-bin/Cargo.toml +++ b/proxy-bin/Cargo.toml @@ -54,6 +54,6 @@ hot_reload = "0.1.4" # logging tracing = { version = "0.1.40" } -tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } url = "2.4.1" dotenv = "0.15.0" diff --git a/proxy-lib/src/http_client/http_client_main.rs b/proxy-lib/src/http_client/http_client_main.rs index 5143d2d..547d8f6 100644 --- a/proxy-lib/src/http_client/http_client_main.rs +++ b/proxy-lib/src/http_client/http_client_main.rs @@ -1,6 +1,7 @@ use crate::{ error::*, trait_resolve_ips::{resolve_ips, ResolveIpResponse, ResolveIps}, + ProxyConfig, }; use reqwest::{header::HeaderMap, Client, IntoUrl, RequestBuilder, Url}; use std::sync::Arc; @@ -32,13 +33,14 @@ pub struct HttpClient { impl HttpClient { /// Build HttpClient pub async fn new( + proxy_config: &ProxyConfig, endpoints: &[Url], - timeout_sec: Duration, - user_agent: &str, default_headers: Option<&HeaderMap>, resolver_ips: impl ResolveIps, - endpoint_resolution_period_sec: Duration, ) -> Result { + let timeout_sec = proxy_config.http_timeout_sec; + let user_agent = &proxy_config.http_user_agent; + let endpoint_resolution_period_sec = proxy_config.endpoint_resolution_period_sec; let resolved_ips = resolve_ips(endpoints, resolver_ips).await?; Ok(Self { inner: Arc::new(RwLock::new( diff --git a/proxy-lib/src/lib.rs b/proxy-lib/src/lib.rs index d243d16..3a8e34c 100644 --- a/proxy-lib/src/lib.rs +++ b/proxy-lib/src/lib.rs @@ -53,15 +53,7 @@ pub async fn entrypoint( if let Some(auth) = &proxy_config.authentication_config { endpoint_candidates.push(auth.token_api.clone()); } - let http_client = HttpClient::new( - &endpoint_candidates, - proxy_config.http_timeout_sec, - &proxy_config.http_user_agent, - None, - bootstrap_dns_resolver.clone(), - proxy_config.endpoint_resolution_period_sec, - ) - .await?; + let http_client = HttpClient::new(proxy_config, &endpoint_candidates, None, bootstrap_dns_resolver.clone()).await?; let http_client = Arc::new(http_client); // spawn authentication service