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:
@@ -6,6 +6,7 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[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"] }
|
||||
packet = { path = "./packet" }
|
||||
bytes = "1.5.0"
|
||||
|
||||
@@ -112,7 +112,7 @@ where
|
||||
url = redirect.to_string();
|
||||
}
|
||||
println!("Location:{}", url);
|
||||
log::info!("最终地址: {}", url);
|
||||
log::info!("修改后的重定向地址: {}", url);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
+62
-45
@@ -149,7 +149,7 @@ pub fn dns_query_all(
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
let end_index = current_domain
|
||||
.rfind(':')
|
||||
.with_context(|| format!("{:?} not port", current_domain))?;
|
||||
@@ -235,56 +235,73 @@ fn check_for_redirect(domain: &String) -> anyhow::Result<Option<String>> {
|
||||
} else {
|
||||
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 请求
|
||||
let response = match Request::new(&uri)
|
||||
.timeout(Duration::from_secs(20))
|
||||
.redirect_policy(RedirectPolicy::Limit(0))
|
||||
.send(&mut response_body)
|
||||
{
|
||||
Ok(resp) => {
|
||||
println!("HTTP Status Code: {}", resp.status_code());
|
||||
resp
|
||||
loop {
|
||||
count += 1;
|
||||
if count > 3 {
|
||||
println!("重定向次数超过 3 次,跳过");
|
||||
return Ok(last_redirect_url);
|
||||
}
|
||||
Err(_) => {
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
|
||||
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();
|
||||
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()));
|
||||
// 解析 URL
|
||||
let uri = match Uri::try_from(url.as_str()) {
|
||||
Ok(u) => {
|
||||
u
|
||||
}
|
||||
}
|
||||
return Ok(None);
|
||||
Err(e) => {
|
||||
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:// 前缀
|
||||
|
||||
Reference in New Issue
Block a user