Merge branch 'refs/heads/main' into 1.2.x

# Conflicts:
#	vnt/src/channel/ws_channel.rs
#	vnt/src/util/dns_query.rs
This commit is contained in:
lbl
2025-06-28 14:57:29 +08:00
3 changed files with 64 additions and 46 deletions
+1
View File
@@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
http_req = { git = "https://github.com/lmq8267/http_req.git", default-features = false, features = ["rust-tls"] }
tun-rs = { version = "2", optional = true, features = ["experimental"] } tun-rs = { version = "2", optional = true, features = ["experimental"] }
packet = { path = "./packet" } packet = { path = "./packet" }
bytes = "1.5.0" bytes = "1.5.0"
+1 -1
View File
@@ -112,7 +112,7 @@ where
url = redirect.to_string(); url = redirect.to_string();
} }
println!("Location{}", url); println!("Location{}", url);
log::info!("最终地址: {}", url); log::info!("修改后的重定向地址: {}", url);
continue; continue;
} }
} }
+26 -9
View File
@@ -235,12 +235,25 @@ fn check_for_redirect(domain: &String) -> anyhow::Result<Option<String>> {
} else { } else {
format!("http://{}", domain) format!("http://{}", domain)
}; };
let mut count = 0; // 重定向次数计数器
let mut last_redirect_url: Option<String> = None; // 记录最后一个重定向的 URL
loop {
count += 1;
if count > 3 {
println!("重定向次数超过 3 次,跳过");
return Ok(last_redirect_url);
}
// 解析 URL // 解析 URL
let uri = match Uri::try_from(url.as_str()) { let uri = match Uri::try_from(url.as_str()) {
Ok(u) => u, Ok(u) => {
u
}
Err(e) => { Err(e) => {
println!("解析地址失败: {}", e); println!("解析地址失败: {}", e);
return Ok(None); return Ok(last_redirect_url);
} }
}; };
@@ -248,7 +261,7 @@ fn check_for_redirect(domain: &String) -> anyhow::Result<Option<String>> {
// 发送 HTTP 请求 // 发送 HTTP 请求
let response = match Request::new(&uri) let response = match Request::new(&uri)
.timeout(Duration::from_secs(20)) .timeout(Duration::from_secs(10))
.redirect_policy(RedirectPolicy::Limit(0)) .redirect_policy(RedirectPolicy::Limit(0))
.send(&mut response_body) .send(&mut response_body)
{ {
@@ -256,8 +269,8 @@ fn check_for_redirect(domain: &String) -> anyhow::Result<Option<String>> {
println!("HTTP Status Code: {}", resp.status_code()); println!("HTTP Status Code: {}", resp.status_code());
resp resp
} }
Err(_) => { Err(e) => {
return Ok(None); return Ok(last_redirect_url);
} }
}; };
@@ -268,13 +281,16 @@ fn check_for_redirect(domain: &String) -> anyhow::Result<Option<String>> {
if response.status_code().is_redirect() { if response.status_code().is_redirect() {
if let Some(location) = response.headers().get("Location") { if let Some(location) = response.headers().get("Location") {
url = location.to_string().trim_end_matches('/').to_string(); url = location.to_string().trim_end_matches('/').to_string();
last_redirect_url = Some(url.clone()); // 更新最后的重定向地址
println!("Location: {}", url); println!("Location: {}", url);
return Ok(Some(url)); continue;
} else {
return Ok(last_redirect_url);
} }
} }
// 处理 200 响应 // 处理 200 响应
if response.status_code().is_success() { else if response.status_code().is_success() {
for line in body_str.lines() { for line in body_str.lines() {
let trimmed = line.trim(); let trimmed = line.trim();
if parse_host_port(trimmed) { if parse_host_port(trimmed) {
@@ -282,9 +298,10 @@ fn check_for_redirect(domain: &String) -> anyhow::Result<Option<String>> {
return Ok(Some(trimmed.to_string())); return Ok(Some(trimmed.to_string()));
} }
} }
return Ok(None); return Ok(last_redirect_url);
}
return Ok(last_redirect_url);
} }
Ok(None)
} }
/// 去掉 http:// 或 https:// 前缀 /// 去掉 http:// 或 https:// 前缀