Skip to content

Commit 7e272f6

Browse files
committed
feat: online-config set http User-Agent and timeouts
1 parent c637d87 commit 7e272f6

File tree

3 files changed

+120
-30
lines changed

3 files changed

+120
-30
lines changed

Cargo.lock

Lines changed: 91 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,20 @@ reqwest = { version = "0.12", features = [
260260
"blocking",
261261
"rustls-tls",
262262
"rustls-tls-native-roots",
263+
"deflate",
264+
"gzip",
265+
"brotli",
266+
"zstd",
263267
], default-features = false, optional = true }
264268

265269
[target.'cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))'.dependencies]
266270
reqwest = { version = "0.12", features = [
267271
"blocking",
268272
"native-tls-vendored",
273+
"deflate",
274+
"gzip",
275+
"brotli",
276+
"zstd",
269277
], optional = true }
270278

271279
[dev-dependencies]

src/service/local.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,30 @@ async fn get_online_config_servers(
10971097
online_config_url: &str,
10981098
) -> Result<Vec<ServerInstanceConfig>, Box<dyn std::error::Error>> {
10991099
use log::warn;
1100+
use reqwest::{redirect::Policy, Client};
11001101

11011102
#[inline]
11021103
async fn get_online_config(online_config_url: &str) -> reqwest::Result<String> {
1103-
let response = reqwest::get(online_config_url).await?;
1104+
static SHADOWSOCKS_USER_AGENT: &str = concat!(
1105+
env!("CARGO_PKG_NAME"),
1106+
"/",
1107+
env!("CARGO_PKG_VERSION"),
1108+
);
1109+
1110+
1111+
let client = Client::builder()
1112+
.user_agent(SHADOWSOCKS_USER_AGENT)
1113+
.deflate(true)
1114+
.gzip(true)
1115+
.deflate(true)
1116+
.zstd(true)
1117+
.redirect(Policy::limited(3))
1118+
.timeout(Duration::from_secs(30))
1119+
.read_timeout(Duration::from_secs(5))
1120+
.connect_timeout(Duration::from_millis(500))
1121+
.build()?;
1122+
1123+
let response = client.get(online_config_url).send().await?;
11041124
if response.url().scheme() != "https" {
11051125
warn!(
11061126
"SIP008 suggests configuration URL should use https, but current URL is {}",

0 commit comments

Comments
 (0)