@@ -49,8 +49,6 @@ async fn get_bufsize(cx: &RouteContext<()>) -> usize {
4949}
5050
5151pub async fn handler ( req : Request , cx : RouteContext < ( ) > ) -> Result < Response > {
52- console_debug ! ( "Request url: {:?}" , req. url( ) . unwrap( ) ) ;
53-
5452 let pre = PREFIXTJ . get_or_init ( || async {
5553 get_prefix_trojan ( & cx) . await
5654 } ) . await ;
@@ -61,16 +59,25 @@ pub async fn handler(req: Request, cx: RouteContext<()>) -> Result<Response> {
6159 let reg = APIREGEX . get_or_init ( || async {
6260 get_regex ( ) . await
6361 } ) . await ;
64-
62+
63+ let query = match req. url ( ) {
64+ Ok ( url) => url. query ( ) . unwrap_or ( "" ) . to_string ( ) ,
65+ Err ( _) => "" . to_string ( ) ,
66+ } ;
6567 if let Some ( captures) = reg. captures ( req. path ( ) . as_str ( ) ) {
6668 let domain = captures. name ( "domain" ) . map_or ( "" , |x| x. as_str ( ) ) ;
6769 let path = captures. name ( "path" ) . map_or ( "" , |x| x. as_str ( ) ) ;
68- let query = captures. name ( "query" ) . map_or ( "" , |x| x. as_str ( ) ) ;
6970
7071 if !domain. contains ( '.' ) {
7172 return Response :: error ( "Not Found" , 404 ) ;
7273 }
73- if let Ok ( url) = format ! ( "https://{}{}{}" , domain, path, query) . parse :: < Uri > ( ) {
74+ let mut full_url = format ! ( "https://{}{}" , domain, path) ;
75+ if !query. is_empty ( ) {
76+ full_url. push ( '?' ) ;
77+ full_url. push_str ( & query) ;
78+ }
79+
80+ if let Ok ( url) = full_url. parse :: < Uri > ( ) {
7481 return api:: handler ( req, url) . await ;
7582 }
7683 }
0 commit comments