@@ -238,8 +238,8 @@ pub fn retrieve_asset(
238238 } else {
239239 // URL not in cache, we retrieve the file
240240 match client. get ( url. as_str ( ) ) . send ( ) {
241- Ok ( mut response) => {
242- if !options. ignore_errors && response. status ( ) != 200 {
241+ Ok ( response) => {
242+ if !options. ignore_errors && response. status ( ) != reqwest :: StatusCode :: OK {
243243 if !options. silent {
244244 eprintln ! (
245245 "{}{}{} ({}){}" ,
@@ -258,19 +258,17 @@ pub fn retrieve_asset(
258258 return Err ( client. get ( "" ) . send ( ) . unwrap_err ( ) ) ;
259259 }
260260
261+ let response_url: Url = response. url ( ) . clone ( ) ;
262+
261263 if !options. silent {
262- if url. as_str ( ) == response . url ( ) . as_str ( ) {
264+ if url. as_str ( ) == response_url . as_str ( ) {
263265 eprintln ! ( "{}{}" , indent( depth) . as_str( ) , & url) ;
264266 } else {
265- eprintln ! ( "{}{} -> {}" , indent( depth) . as_str( ) , & url, & response . url ( ) ) ;
267+ eprintln ! ( "{}{} -> {}" , indent( depth) . as_str( ) , & url, & response_url ) ;
266268 }
267269 }
268270
269- let new_cache_key: String = clean_url ( response. url ( ) . clone ( ) ) . to_string ( ) ;
270-
271- // Convert response into a byte array
272- let mut data: Vec < u8 > = vec ! [ ] ;
273- response. copy_to ( & mut data) . unwrap ( ) ;
271+ let new_cache_key: String = clean_url ( response_url. clone ( ) ) . to_string ( ) ;
274272
275273 // Attempt to obtain media type and charset by reading Content-Type header
276274 let content_type: & str = response
@@ -281,11 +279,34 @@ pub fn retrieve_asset(
281279
282280 let ( media_type, charset, _is_base64) = parse_content_type ( & content_type) ;
283281
282+ // Convert response into a byte array
283+ let mut data: Vec < u8 > = vec ! [ ] ;
284+ match response. bytes ( ) {
285+ Ok ( b) => {
286+ data = b. to_vec ( ) ;
287+ }
288+ Err ( error) => {
289+ if !options. silent {
290+ eprintln ! (
291+ "{}{}{}{}" ,
292+ indent( depth) . as_str( ) ,
293+ if options. no_color { "" } else { ANSI_COLOR_RED } ,
294+ error,
295+ if options. no_color {
296+ ""
297+ } else {
298+ ANSI_COLOR_RESET
299+ } ,
300+ ) ;
301+ }
302+ }
303+ }
304+
284305 // Add retrieved resource to cache
285306 cache. insert ( new_cache_key, data. clone ( ) ) ;
286307
287308 // Return
288- Ok ( ( data, response . url ( ) . clone ( ) , media_type, charset) )
309+ Ok ( ( data, response_url , media_type, charset) )
289310 }
290311 Err ( error) => {
291312 if !options. silent {
0 commit comments