@@ -14,6 +14,7 @@ use sha2::{Digest, Sha256};
14
14
use url:: Url ;
15
15
16
16
use futures:: prelude:: * ;
17
+ use tokio:: runtime:: current_thread:: Runtime ;
17
18
18
19
//use serde_types::AwsError;
19
20
use signing;
@@ -22,6 +23,7 @@ use EMPTY_PAYLOAD_SHA;
22
23
use LONG_DATE ;
23
24
use reqwest:: async:: Response ;
24
25
use error:: { S3Error , S3Result , err} ;
26
+ use std:: error:: Error ;
25
27
26
28
/// Collection of HTTP headers sent to S3 service, in key/value format.
27
29
pub type Headers = HashMap < String , String > ;
@@ -223,17 +225,24 @@ impl<'a> Request<'a> {
223
225
}
224
226
225
227
pub fn response_data ( & self ) -> S3Result < ( Vec < u8 > , u16 ) > {
226
- match self . response_data_future ( ) . wait ( ) {
227
- Ok ( ( response_data, status_code) ) => Ok ( ( response_data, status_code) ) ,
228
- Err ( _) => Err ( S3Error { src : Some ( "Error getting response" . to_string ( ) ) } )
229
- }
228
+ let response_data = self . response_data_future ( ) . then ( |result|
229
+ match result {
230
+ Ok ( ( response_data, status_code) ) => Ok ( ( response_data, status_code) ) ,
231
+ Err ( e) => Err ( e)
232
+ } ) ;
233
+ let mut runtime = Runtime :: new ( ) . unwrap ( ) ;
234
+ runtime. block_on ( response_data)
230
235
}
231
236
232
237
pub fn response_data_to_writer < T : Write > ( & self , writer : & mut T ) -> S3Result < u16 > {
233
- match self . response_data_to_writer_future ( writer) . wait ( ) {
234
- Ok ( status_code) => Ok ( status_code) ,
235
- Err ( _) => Err ( err ( "ReqwestFuture" ) )
236
- }
238
+ let status_code_future = self . response_data_to_writer_future ( writer) . then ( |result| {
239
+ match result {
240
+ Ok ( status_code) => Ok ( status_code) ,
241
+ Err ( _) => Err ( err ( "ReqwestFuture" ) )
242
+ }
243
+ } ) ;
244
+ let mut runtime = Runtime :: new ( ) . unwrap ( ) ;
245
+ runtime. block_on ( status_code_future)
237
246
}
238
247
239
248
pub fn response_future ( & self ) -> impl Future < Item =Response , Error =S3Error > {
@@ -263,14 +272,14 @@ impl<'a> Request<'a> {
263
272
. headers ( headers. to_owned ( ) )
264
273
. body ( content. to_owned ( ) ) ;
265
274
266
- request. send ( ) . map_err ( |_ | S3Error { src : None } )
275
+ request. send ( ) . map_err ( |e | S3Error { src : Some ( e . description ( ) . to_string ( ) ) } )
267
276
}
268
277
269
278
pub fn response_data_future ( & self ) -> impl Future < Item =( Vec < u8 > , u16 ) , Error =S3Error > {
270
279
self . response_future ( )
271
- . and_then ( |mut response| Ok ( ( response. text ( ) , response. status ( ) . as_u16 ( ) ) ) ) . map_err ( |_| S3Error { src : None } )
280
+ . and_then ( |mut response| Ok ( ( response. text ( ) , response. status ( ) . as_u16 ( ) ) ) )
272
281
. and_then ( |( body_future, status_code) | {
273
- body_future. and_then ( move |body| Ok ( ( body. as_bytes ( ) . to_vec ( ) , status_code) ) ) . map_err ( |_ | S3Error { src : None } )
282
+ body_future. and_then ( move |body| Ok ( ( body. as_bytes ( ) . to_vec ( ) , status_code) ) ) . map_err ( |e | S3Error { src : Some ( e . description ( ) . to_string ( ) ) } )
274
283
} )
275
284
}
276
285
@@ -281,15 +290,14 @@ impl<'a> Request<'a> {
281
290
Ok ( status_code)
282
291
} )
283
292
}
284
-
285
293
}
286
294
287
295
#[ cfg( test) ]
288
296
mod tests {
289
297
use bucket:: Bucket ;
290
298
use command:: Command ;
291
299
use credentials:: Credentials ;
292
- use request:: { Request } ;
300
+ use request:: Request ;
293
301
use error:: S3Result ;
294
302
295
303
// Fake keys - otherwise using Credentials::default will use actual user
0 commit comments