| use crate::modules::config::load_app_config; |
| use once_cell::sync::Lazy; |
| use rquest::{Client, Proxy}; |
| use rquest_util::Emulation; |
|
|
| |
| |
| pub static SHARED_CLIENT: Lazy<Client> = Lazy::new(|| create_base_client(15)); |
|
|
| |
| pub static SHARED_CLIENT_LONG: Lazy<Client> = Lazy::new(|| create_base_client(60)); |
|
|
| |
| pub static SHARED_STANDARD_CLIENT: Lazy<Client> = Lazy::new(|| create_standard_client(15)); |
|
|
| |
| pub static SHARED_STANDARD_CLIENT_LONG: Lazy<Client> = Lazy::new(|| create_standard_client(60)); |
|
|
| |
| fn create_base_client(timeout_secs: u64) -> Client { |
| let mut builder = Client::builder() |
| .emulation(Emulation::Chrome123) |
| .timeout(std::time::Duration::from_secs(timeout_secs)); |
|
|
| if let Ok(config) = load_app_config() { |
| let proxy_config = config.proxy.upstream_proxy; |
| if proxy_config.enabled && !proxy_config.url.is_empty() { |
| match Proxy::all(&proxy_config.url) { |
| Ok(proxy) => { |
| builder = builder.proxy(proxy); |
| tracing::info!( |
| "HTTP shared client enabled upstream proxy: {}", |
| proxy_config.url |
| ); |
| } |
| Err(e) => { |
| tracing::error!("invalid_proxy_url: {}, error: {}", proxy_config.url, e); |
| } |
| } |
| } |
| } |
|
|
| tracing::info!("Initialized JA3/TLS Impersonation (Chrome123)"); |
| builder.build().unwrap_or_else(|_| Client::new()) |
| } |
|
|
| |
| pub fn get_client() -> Client { |
| SHARED_CLIENT.clone() |
| } |
|
|
| |
| pub fn get_long_client() -> Client { |
| SHARED_CLIENT_LONG.clone() |
| } |
|
|
| |
| fn create_standard_client(timeout_secs: u64) -> Client { |
| let mut builder = Client::builder() |
| |
| .timeout(std::time::Duration::from_secs(timeout_secs)); |
|
|
| if let Ok(config) = load_app_config() { |
| let proxy_config = config.proxy.upstream_proxy; |
| if proxy_config.enabled && !proxy_config.url.is_empty() { |
| match Proxy::all(&proxy_config.url) { |
| Ok(proxy) => { |
| builder = builder.proxy(proxy); |
| tracing::info!( |
| "HTTP standard client enabled upstream proxy: {}", |
| proxy_config.url |
| ); |
| } |
| Err(e) => { |
| tracing::error!("invalid_proxy_url: {}, error: {}", proxy_config.url, e); |
| } |
| } |
| } |
| } |
|
|
| tracing::info!("Initialized Pure Native Standard Client"); |
| builder.build().unwrap_or_else(|_| Client::new()) |
| } |
|
|
| |
| pub fn get_standard_client() -> Client { |
| SHARED_STANDARD_CLIENT.clone() |
| } |
|
|
| |
| pub fn get_long_standard_client() -> Client { |
| SHARED_STANDARD_CLIENT_LONG.clone() |
| } |
|
|