@@ -8,6 +8,7 @@ use reqwest::{
8
8
Client , ClientBuilder , Response ,
9
9
} ;
10
10
use std:: { collections:: HashMap , str:: FromStr , time:: Duration } ;
11
+ use std:: process:: { Command , Output } ;
11
12
12
13
/// LeetCode API set
13
14
#[ derive( Clone ) ]
@@ -43,7 +44,6 @@ impl LeetCode {
43
44
vec ! [
44
45
( "Cookie" , & cookie) ,
45
46
( "x-csrftoken" , & csrf) ,
46
- ( "x-requested-with" , "XMLHttpRequest" ) ,
47
47
( "Origin" , & conf. sys. urls. base) ,
48
48
] ,
49
49
) ?;
@@ -232,6 +232,40 @@ impl LeetCode {
232
232
. send ( & self . client )
233
233
. await
234
234
}
235
+
236
+ pub fn execute_curl_impersonate ( self , j : Json , url : String , refer : String ) -> Result < Output > {
237
+ let header_csrf_arg = match self . default_headers . get ( "x-csrftoken" ) {
238
+ Some ( value) => format ! ( "x-csrftoken: {}" , value. to_str( ) . unwrap( ) ) ,
239
+ None => String :: new ( )
240
+ } ;
241
+
242
+ let header_referer_arg = format ! ( "Referer: {}" , refer) ;
243
+
244
+ let cookie_arg = match self . default_headers . get ( "Cookie" ) {
245
+ Some ( value) => format ! ( "{}" , value. to_str( ) . unwrap( ) ) ,
246
+ None => String :: new ( )
247
+ } ;
248
+
249
+ let data_arg = match serde_json:: to_string ( & j) {
250
+ Ok ( value) => format ! ( "{}" , value) ,
251
+ Err ( _) => String :: new ( )
252
+ } ;
253
+
254
+ let output = Command :: new ( "curl_ff117" )
255
+ . arg ( "--header" )
256
+ . arg ( & header_csrf_arg)
257
+ . arg ( "--header" )
258
+ . arg ( & header_referer_arg)
259
+ . arg ( "--cookie" )
260
+ . arg ( & cookie_arg)
261
+ . arg ( "--data" )
262
+ . arg ( & data_arg)
263
+ . arg ( & url)
264
+ . output ( )
265
+ . expect ( "Failed to execute process" ) ;
266
+ trace ! ( "{:?}" , output) ;
267
+ Ok ( output)
268
+ }
235
269
236
270
/// Get the result of submission / testing
237
271
pub async fn verify_result ( self , id : String ) -> Result < Response > {
0 commit comments