@@ -239,7 +239,7 @@ async fn fetch_with_meta(
239239 response_info. insert ( "status" . to_string ( ) , response. status ( ) . as_u16 ( ) . into ( ) ) ;
240240
241241 let mut headers = serde_json:: Map :: new ( ) ;
242- for ( name, value) in response. headers ( ) . iter ( ) {
242+ for ( name, value) in response. headers ( ) {
243243 if let Ok ( value_str) = value. to_str ( ) {
244244 headers. insert ( name. to_string ( ) , value_str. into ( ) ) ;
245245 }
@@ -261,32 +261,27 @@ async fn fetch_with_meta(
261261 String :: from_utf8_lossy ( & body_bytes) . into_owned ( ) ,
262262 ) ,
263263 }
264- } else {
265- match String :: from_utf8 ( body_bytes. clone ( ) ) {
266- Ok ( text) => serde_json:: Value :: String ( text) ,
267- Err ( _) => {
268- let mut base64_string = String :: new ( ) ;
269- base64:: Engine :: encode_string (
270- & base64:: engine:: general_purpose:: STANDARD ,
271- & body_bytes,
272- & mut base64_string,
273- ) ;
274- serde_json:: Value :: String ( base64_string)
275- }
276- }
264+ } else if let Ok ( text) = String :: from_utf8 ( body_bytes. clone ( ) ) { serde_json:: Value :: String ( text) } else {
265+ let mut base64_string = String :: new ( ) ;
266+ base64:: Engine :: encode_string (
267+ & base64:: engine:: general_purpose:: STANDARD ,
268+ & body_bytes,
269+ & mut base64_string,
270+ ) ;
271+ serde_json:: Value :: String ( base64_string)
277272 } ;
278273 response_info. insert ( "body" . to_string ( ) , body_value) ;
279274 }
280275 Err ( e) => {
281276 response_info. insert (
282277 "error" . to_string ( ) ,
283- format ! ( "Failed to read response body: {}" , e ) . into ( ) ,
278+ format ! ( "Failed to read response body: {e}" ) . into ( ) ,
284279 ) ;
285280 }
286281 }
287282 }
288283 Err ( e) => {
289- response_info. insert ( "error" . to_string ( ) , format ! ( "Request failed: {}" , e ) . into ( ) ) ;
284+ response_info. insert ( "error" . to_string ( ) , format ! ( "Request failed: {e}" ) . into ( ) ) ;
290285 }
291286 }
292287
0 commit comments