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;
} }
} }
+62 -45
View File
@@ -149,7 +149,7 @@ pub fn dns_query_all(
} }
continue; continue;
} }
let end_index = current_domain let end_index = current_domain
.rfind(':') .rfind(':')
.with_context(|| format!("{:?} not port", current_domain))?; .with_context(|| format!("{:?} not port", current_domain))?;
@@ -235,56 +235,73 @@ fn check_for_redirect(domain: &String) -> anyhow::Result<Option<String>> {
} else { } else {
format!("http://{}", domain) format!("http://{}", domain)
}; };
// 解析 URL
let uri = match Uri::try_from(url.as_str()) {
Ok(u) => u,
Err(e) => {
println!("解析地址失败: {}", e);
return Ok(None);
}
};
let mut response_body = Vec::new(); let mut count = 0; // 重定向次数计数器
let mut last_redirect_url: Option<String> = None; // 记录最后一个重定向的 URL
// 发送 HTTP 请求 loop {
let response = match Request::new(&uri) count += 1;
.timeout(Duration::from_secs(20)) if count > 3 {
.redirect_policy(RedirectPolicy::Limit(0)) println!("重定向次数超过 3 次,跳过");
.send(&mut response_body) return Ok(last_redirect_url);
{
Ok(resp) => {
println!("HTTP Status Code: {}", resp.status_code());
resp
} }
Err(_) => {
return Ok(None);
}
};
let body_str = String::from_utf8_lossy(&response_body); // 解析 URL
let cleaned_body = body_str.replace('\n', "").replace('\r', ""); let uri = match Uri::try_from(url.as_str()) {
println!("Response Body: {}", cleaned_body); Ok(u) => {
// 处理 3XX 重定向 u
if response.status_code().is_redirect() {
if let Some(location) = response.headers().get("Location") {
url = location.to_string().trim_end_matches('/').to_string();
println!("Location: {}", url);
return Ok(Some(url));
}
}
// 处理 200 响应
if response.status_code().is_success() {
for line in body_str.lines() {
let trimmed = line.trim();
if parse_host_port(trimmed) {
println!("text: {}", trimmed);
return Ok(Some(trimmed.to_string()));
} }
} Err(e) => {
return Ok(None); println!("解析地址失败: {}", e);
return Ok(last_redirect_url);
}
};
let mut response_body = Vec::new();
// 发送 HTTP 请求
let response = match Request::new(&uri)
.timeout(Duration::from_secs(10))
.redirect_policy(RedirectPolicy::Limit(0))
.send(&mut response_body)
{
Ok(resp) => {
println!("HTTP Status Code: {}", resp.status_code());
resp
}
Err(e) => {
return Ok(last_redirect_url);
}
};
let body_str = String::from_utf8_lossy(&response_body);
let cleaned_body = body_str.replace('\n', "").replace('\r', "");
println!("Response Body: {}", cleaned_body);
// 处理 3XX 重定向
if response.status_code().is_redirect() {
if let Some(location) = response.headers().get("Location") {
url = location.to_string().trim_end_matches('/').to_string();
last_redirect_url = Some(url.clone()); // 更新最后的重定向地址
println!("Location: {}", url);
continue;
} else {
return Ok(last_redirect_url);
}
}
// 处理 200 响应
else if response.status_code().is_success() {
for line in body_str.lines() {
let trimmed = line.trim();
if parse_host_port(trimmed) {
println!("text: {}", trimmed);
return Ok(Some(trimmed.to_string()));
}
}
return Ok(last_redirect_url);
}
return Ok(last_redirect_url);
} }
Ok(None)
} }
/// 去掉 http:// 或 https:// 前缀 /// 去掉 http:// 或 https:// 前缀