diff --git a/src/utils/request.rs b/src/utils/http.rs similarity index 73% rename from src/utils/request.rs rename to src/utils/http.rs index e96d74b..f5f967a 100644 --- a/src/utils/request.rs +++ b/src/utils/http.rs @@ -1,12 +1,31 @@ +use crate::types::GeminiKey; +use crate::{config::KeyCheckerConfig, error::ValidatorError}; use backon::{ExponentialBuilder, Retryable}; use reqwest::Client; use serde::Serialize; -use tokio::time::Duration; +use std::time::Duration; +use tokio::time::Duration as TokioDuration; use tracing::debug; use url::Url; -use crate::error::ValidatorError; -use crate::types::GeminiKey; +pub fn client_builder(config: &KeyCheckerConfig) -> Result { + // Set the maximum number of connections per host based on concurrency. + let pool_size = config.concurrency / 2; + + let mut builder = Client::builder() + .timeout(Duration::from_secs(config.timeout_sec)) + .pool_max_idle_per_host(pool_size); + + if let Some(ref proxy_url) = config.proxy { + builder = builder.proxy(reqwest::Proxy::all(proxy_url.clone())?); + } + + if !config.enable_multiplexing { + builder = builder.http1_only(); + } + + Ok(builder.build()?) +} pub async fn send_request( client: Client, @@ -20,8 +39,8 @@ where { let retry_policy = ExponentialBuilder::default() .with_max_times(max_retries) - .with_min_delay(Duration::from_secs(1)) - .with_max_delay(Duration::from_secs(2)); + .with_min_delay(TokioDuration::from_secs(1)) + .with_max_delay(TokioDuration::from_secs(2)); (async || { let response = client diff --git a/src/utils/http_client.rs b/src/utils/http_client.rs deleted file mode 100644 index 3fb86eb..0000000 --- a/src/utils/http_client.rs +++ /dev/null @@ -1,22 +0,0 @@ -use crate::{config::KeyCheckerConfig, error::ValidatorError}; -use reqwest::Client; -use std::time::Duration; - -pub fn client_builder(config: &KeyCheckerConfig) -> Result { - // Set the maximum number of connections per host based on concurrency. - let pool_size = config.concurrency / 2; - - let mut builder = Client::builder() - .timeout(Duration::from_secs(config.timeout_sec)) - .pool_max_idle_per_host(pool_size); - - if let Some(ref proxy_url) = config.proxy { - builder = builder.proxy(reqwest::Proxy::all(proxy_url.clone())?); - } - - if !config.enable_multiplexing { - builder = builder.http1_only(); - } - - Ok(builder.build()?) -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 53cd21a..7d723a4 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,5 +1,3 @@ -pub mod http_client; -pub mod request; +pub mod http; -pub use http_client::client_builder; -pub use request::send_request; \ No newline at end of file +pub use http::{client_builder, send_request}; diff --git a/src/validation/validation_service.rs b/src/validation/validation_service.rs index 050a046..21b8eea 100644 --- a/src/validation/validation_service.rs +++ b/src/validation/validation_service.rs @@ -101,13 +101,10 @@ impl ValidationService { pub async fn start_validation() -> Result<(), ValidatorError> { let config = KeyCheckerConfig::load_config()?; - // 加载密钥 let keys = load_keys_from_txt(config.input_path.as_path())?; - // 构建HTTP客户端 let client = client_builder(&config)?; - // 创建验证服务并启动 let validation_service = ValidationService::new(config, client); validation_service.validate_keys(keys).await }