@@ -43,27 +43,27 @@ fn full<T: Into<Bytes>>(chunk: T) -> BoxBody {
4343/// Normalize target URL from various shorthand formats
4444fn normalize_target ( target : & str ) -> String {
4545 let target = target. trim ( ) ;
46-
46+
4747 // If it already starts with http:// or https://, return as is
4848 if target. starts_with ( "http://" ) || target. starts_with ( "https://" ) {
4949 return target. to_string ( ) ;
5050 }
51-
51+
5252 // If it's just a port number (e.g., "3000")
5353 if target. parse :: < u16 > ( ) . is_ok ( ) {
5454 return format ! ( "http://localhost:{}" , target) ;
5555 }
56-
56+
5757 // If it starts with : (e.g., ":3000")
5858 if target. starts_with ( ':' ) {
5959 return format ! ( "http://localhost{}" , target) ;
6060 }
61-
61+
6262 // If it's localhost:port or 127.0.0.1:port format (no protocol)
6363 if !target. contains ( "://" ) {
6464 return format ! ( "http://{}" , target) ;
6565 }
66-
66+
6767 // Default: assume it's meant to be http
6868 format ! ( "http://{}" , target)
6969}
@@ -114,7 +114,7 @@ async fn handle_request(
114114 . path_and_query ( )
115115 . map ( |pq| pq. as_str ( ) )
116116 . unwrap_or ( "/" ) ;
117-
117+
118118 let target_url = format ! ( "{}{}" , target. trim_end_matches( '/' ) , path_and_query) ;
119119
120120 // Create client request
@@ -124,9 +124,7 @@ async fn handle_request(
124124 let ( parts, body) = req. into_parts ( ) ;
125125 let body_bytes = body. collect ( ) . await ?. to_bytes ( ) ;
126126
127- let mut proxy_req = Request :: builder ( )
128- . method ( parts. method )
129- . uri ( & target_url) ;
127+ let mut proxy_req = Request :: builder ( ) . method ( parts. method ) . uri ( & target_url) ;
130128
131129 // Copy headers
132130 for ( key, value) in parts. headers . iter ( ) {
@@ -142,12 +140,12 @@ async fn handle_request(
142140 Ok ( response) => {
143141 let ( parts, body) = response. into_parts ( ) ;
144142 let body_bytes = body. collect ( ) . await ?. to_bytes ( ) ;
145-
143+
146144 let mut builder = Response :: builder ( ) . status ( parts. status ) ;
147145 for ( key, value) in parts. headers . iter ( ) {
148146 builder = builder. header ( key, value) ;
149147 }
150-
148+
151149 Ok ( builder. body ( full ( body_bytes) ) . unwrap ( ) )
152150 }
153151 Err ( _) => Ok ( Response :: builder ( )
@@ -160,7 +158,7 @@ async fn handle_request(
160158#[ tokio:: main]
161159async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
162160 let args = Args :: parse ( ) ;
163-
161+
164162 // Normalize target URL to support shorthand formats
165163 let target = normalize_target ( & args. target ) ;
166164
0 commit comments