Add 10s timeout to fetch_proxy_config and download_proxy_secret

This commit is contained in:
ivulit 2026-02-23 15:30:27 +03:00
parent 836eb6f777
commit 39dfc07cbd
No known key found for this signature in database
2 changed files with 15 additions and 4 deletions

View File

@ -77,10 +77,15 @@ fn parse_proxy_line(line: &str) -> Option<(i32, IpAddr, u16)> {
} }
pub async fn fetch_proxy_config(url: &str) -> Result<ProxyConfigData> { pub async fn fetch_proxy_config(url: &str) -> Result<ProxyConfigData> {
let resp = reqwest::get(url) let client = reqwest::Client::builder()
.timeout(Duration::from_secs(10))
.build()
.map_err(|e| crate::error::ProxyError::Proxy(format!("fetch_proxy_config client build failed: {e}")))?;
let resp = client
.get(url)
.send()
.await .await
.map_err(|e| crate::error::ProxyError::Proxy(format!("fetch_proxy_config GET failed: {e}")))? .map_err(|e| crate::error::ProxyError::Proxy(format!("fetch_proxy_config GET failed: {e}")))?;
;
if let Some(date) = resp.headers().get(reqwest::header::DATE) { if let Some(date) = resp.headers().get(reqwest::header::DATE) {
if let Ok(date_str) = date.to_str() { if let Ok(date_str) = date.to_str() {

View File

@ -54,7 +54,13 @@ pub async fn fetch_proxy_secret(cache_path: Option<&str>) -> Result<Vec<u8>> {
} }
pub async fn download_proxy_secret() -> Result<Vec<u8>> { pub async fn download_proxy_secret() -> Result<Vec<u8>> {
let resp = reqwest::get("https://core.telegram.org/getProxySecret") let client = reqwest::Client::builder()
.timeout(Duration::from_secs(10))
.build()
.map_err(|e| ProxyError::Proxy(format!("Failed to build reqwest client: {e}")))?;
let resp = client
.get("https://core.telegram.org/getProxySecret")
.send()
.await .await
.map_err(|e| ProxyError::Proxy(format!("Failed to download proxy-secret: {e}")))?; .map_err(|e| ProxyError::Proxy(format!("Failed to download proxy-secret: {e}")))?;