mirror of
https://github.com/TeamPiped/piped-proxy.git
synced 2024-08-14 23:50:45 +00:00
Make clippy happy.
This commit is contained in:
parent
44d1a0a053
commit
f44df15206
1 changed files with 17 additions and 11 deletions
28
src/main.rs
28
src/main.rs
|
@ -13,9 +13,9 @@ use reqwest::{Client, Request, Url};
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
println!("Running server!");
|
println!("Running server!");
|
||||||
|
|
||||||
let server =HttpServer::new(|| {
|
let server = HttpServer::new(|| {
|
||||||
// match all requests
|
// match all requests
|
||||||
App::new()
|
App::new()
|
||||||
.default_service(web::to(index))
|
.default_service(web::to(index))
|
||||||
});
|
});
|
||||||
// get port from env
|
// get port from env
|
||||||
|
@ -60,10 +60,14 @@ fn is_header_allowed(header: &str) -> bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
match header {
|
!matches!(header, "host" |
|
||||||
"host" | "content-length" | "set-cookie" | "alt-svc" | "accept-ch" | "report-to" | "strict-transport-security" => false,
|
"content-length" |
|
||||||
_ => true,
|
"set-cookie" |
|
||||||
}
|
"alt-svc" |
|
||||||
|
"accept-ch" |
|
||||||
|
"report-to" |
|
||||||
|
"strict-transport-security" |
|
||||||
|
"user-agent")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
||||||
|
@ -117,6 +121,8 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
||||||
|
|
||||||
let request_headers = request.headers_mut();
|
let request_headers = request.headers_mut();
|
||||||
|
|
||||||
|
request_headers.insert("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0".parse().unwrap());
|
||||||
|
|
||||||
for (key, value) in req.headers() {
|
for (key, value) in req.headers() {
|
||||||
if is_header_allowed(key.as_str()) {
|
if is_header_allowed(key.as_str()) {
|
||||||
request_headers.insert(key.clone(), value.clone());
|
request_headers.insert(key.clone(), value.clone());
|
||||||
|
@ -167,8 +173,8 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
||||||
|
|
||||||
let modified = resp_str.lines().map(|line| {
|
let modified = resp_str.lines().map(|line| {
|
||||||
let captures = RE_MANIFEST.captures(line);
|
let captures = RE_MANIFEST.captures(line);
|
||||||
if captures.is_some() {
|
if let Some(captures) = captures {
|
||||||
let url = captures.unwrap().get(1).unwrap().as_str();
|
let url = captures.get(1).unwrap().as_str();
|
||||||
if url.starts_with("https://") {
|
if url.starts_with("https://") {
|
||||||
return line.replace(url, localize_url(url, host).as_str());
|
return line.replace(url, localize_url(url, host).as_str());
|
||||||
}
|
}
|
||||||
|
@ -196,12 +202,12 @@ fn localize_url(url: &str, host: &str) -> String {
|
||||||
.append_pair("host", &host);
|
.append_pair("host", &host);
|
||||||
|
|
||||||
return format!("{}?{}", url.path(), url.query().unwrap());
|
return format!("{}?{}", url.path(), url.query().unwrap());
|
||||||
} else if url.starts_with("/") {
|
} else if url.starts_with('/') {
|
||||||
return if url.contains("?") {
|
return if url.contains('?') {
|
||||||
format!("{}&host={}", url, host)
|
format!("{}&host={}", url, host)
|
||||||
} else {
|
} else {
|
||||||
format!("{}?host={}", url, host)
|
format!("{}?host={}", url, host)
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
url.to_string()
|
url.to_string()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue