mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-15 08:34:43 +01:00
simplify proxy request handling
This commit is contained in:
@@ -44,28 +44,25 @@ pub fn set_proxy_addr(addr: String){
|
|||||||
impl HttpHandler for ProxyHandler {
|
impl HttpHandler for ProxyHandler {
|
||||||
async fn handle_request(&mut self,
|
async fn handle_request(&mut self,
|
||||||
_context: &HttpContext,
|
_context: &HttpContext,
|
||||||
request: Request<Body>
|
mut request: Request<Body>
|
||||||
) -> RequestOrResponse {
|
) -> RequestOrResponse {
|
||||||
// Get request parts.
|
println!("Request: {}", &request.uri());
|
||||||
let (parts, body) = request.into_parts();
|
|
||||||
|
|
||||||
// Parse request URI.
|
// Get request URI
|
||||||
let mut uri = parts.uri.clone();
|
let uri = request.uri().to_string();
|
||||||
let path = uri.to_string();
|
let uri_path = request.uri().path();
|
||||||
|
|
||||||
// Check URI against constraints.
|
// Only switch up if request is to the game servers
|
||||||
if path.contains("hoyoverse.com") || path.contains("mihoyo.com") || path.contains("yuanshen.com") {
|
if uri.contains("hoyoverse.com") || uri.contains("mihoyo.com") || uri.contains("yuanshen.com") {
|
||||||
println!("uri path: {}{}", *SERVER.lock().unwrap(), uri.path());
|
// Copy the request and just change the URI
|
||||||
uri = format!("https://{}{}", *SERVER.lock().unwrap(), uri.path()).parse::<Uri>().unwrap();
|
let uri = format!("https://{}{}", SERVER.lock().unwrap(), uri_path).parse::<Uri>().unwrap();
|
||||||
|
|
||||||
|
*request.uri_mut() = uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
let builder = Request::builder()
|
println!("New request: {}", &request.uri());
|
||||||
.method(&parts.method)
|
|
||||||
.uri(&uri)
|
|
||||||
.version(parts.version);
|
|
||||||
let modified = builder.body(body).unwrap();
|
|
||||||
|
|
||||||
RequestOrResponse::Request(modified)
|
RequestOrResponse::Request(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_response(&mut self,
|
async fn handle_response(&mut self,
|
||||||
|
|||||||
Reference in New Issue
Block a user