@@ -44,10 +44,10 @@ async fn connect_through_proxy(
4444 80
4545 } ) ;
4646
47- let proxy_addr = format ! ( "{}:{}" , proxy_host , proxy_port ) ;
47+ let proxy_addr = format ! ( "{proxy_host }:{proxy_port}" ) ;
4848 let mut stream = TcpStream :: connect ( & proxy_addr)
4949 . await
50- . context ( format ! ( "Failed to connect to proxy at {}" , proxy_addr ) ) ?;
50+ . context ( format ! ( "Failed to connect to proxy at {proxy_addr}" ) ) ?;
5151
5252 let target_host = target_url
5353 . host_str ( )
@@ -60,23 +60,18 @@ async fn connect_through_proxy(
6060 80
6161 } ) ;
6262
63- let mut connect_request = format ! (
64- "CONNECT {}:{} HTTP/1.1\r \n Host: {}:{}\r \n " ,
65- target_host, target_port, target_host, target_port
66- ) ;
63+ let mut connect_request =
64+ format ! ( "CONNECT {target_host}:{target_port} HTTP/1.1\r \n Host: {target_host}:{target_port}\r \n " ) ;
6765
6866 let username = proxy_url. username ( ) ;
6967 if !username. is_empty ( ) {
7068 let password = proxy_url. password ( ) . unwrap_or ( "" ) ;
71- let credentials = format ! ( "{}:{}" , username , password ) ;
69+ let credentials = format ! ( "{username }:{password}" ) ;
7270 let encoded = base64:: engine:: general_purpose:: STANDARD . encode ( credentials. as_bytes ( ) ) ;
73- connect_request = format ! (
74- "{}Proxy-Authorization: Basic {}\r \n " ,
75- connect_request, encoded
76- ) ;
71+ connect_request = format ! ( "{connect_request}Proxy-Authorization: Basic {encoded}\r \n " ) ;
7772 }
7873
79- connect_request = format ! ( "{}\r \n " , connect_request ) ;
74+ connect_request = format ! ( "{connect_request }\r \n " ) ;
8075
8176 stream
8277 . write_all ( connect_request. as_bytes ( ) )
@@ -89,7 +84,11 @@ async fn connect_through_proxy(
8984 . await
9085 . context ( "Failed to read CONNECT response from proxy" ) ?;
9186
92- let response_str = String :: from_utf8_lossy ( & response[ ..n] ) ;
87+ let response_str = String :: from_utf8_lossy (
88+ response
89+ . get ( ..n)
90+ . context ( "Invalid response slice range" ) ?,
91+ ) ;
9392
9493 if !response_str. starts_with ( "HTTP/1.1 200" ) && !response_str. starts_with ( "HTTP/1.0 200" ) {
9594 bail ! (
@@ -104,7 +103,7 @@ async fn connect_through_proxy(
104103 let headers = req. headers_mut ( ) ;
105104 headers. insert (
106105 "Authorization" ,
107- HeaderValue :: from_str ( & format ! ( "Bearer {}" , token ) ) ?,
106+ HeaderValue :: from_str ( & format ! ( "Bearer {token}" ) ) ?,
108107 ) ;
109108
110109 let maybe_tls_stream = if target_url. scheme ( ) == "wss" {
0 commit comments