@@ -18,6 +18,8 @@ use http::{Method, Request, Response, StatusCode};
1818use http_body_util:: { BodyExt , Full } ;
1919use httpdate:: HttpDate ;
2020#[ cfg( feature = "hyper-rustls" ) ]
21+ use hyper:: body:: Incoming ;
22+ #[ cfg( feature = "hyper-rustls" ) ]
2123use hyper_util:: client:: legacy:: Client as HyperClient ;
2224#[ cfg( feature = "hyper-rustls" ) ]
2325use hyper_util:: client:: legacy:: connect:: { Connect , HttpConnector } ;
@@ -211,12 +213,7 @@ impl HttpClient for DefaultClient {
211213 req : Request < Full < Bytes > > ,
212214 ) -> Pin < Box < dyn Future < Output = Result < BytesResponse , Error > > + Send > > {
213215 let fut = self . 0 . request ( req) ;
214- Box :: pin ( async move {
215- match fut. await {
216- Ok ( rsp) => Ok ( BytesResponse :: from ( rsp) ) ,
217- Err ( e) => Err ( e. into ( ) ) ,
218- }
219- } )
216+ Box :: pin ( async move { BytesResponse :: try_from ( fut. await ) } )
220217 }
221218}
222219
@@ -236,12 +233,7 @@ impl<C: Connect + Clone + Send + Sync + 'static> HttpClient for HyperClient<C, F
236233 req : Request < Full < Bytes > > ,
237234 ) -> Pin < Box < dyn Future < Output = Result < BytesResponse , Error > > + Send > > {
238235 let fut = self . request ( req) ;
239- Box :: pin ( async move {
240- match fut. await {
241- Ok ( rsp) => Ok ( BytesResponse :: from ( rsp) ) ,
242- Err ( e) => Err ( e. into ( ) ) ,
243- }
244- } )
236+ Box :: pin ( async move { BytesResponse :: try_from ( fut. await ) } )
245237 }
246238}
247239
@@ -254,6 +246,16 @@ pub struct BytesResponse {
254246}
255247
256248impl BytesResponse {
249+ #[ cfg( feature = "hyper-rustls" ) ]
250+ fn try_from (
251+ result : Result < Response < Incoming > , hyper_util:: client:: legacy:: Error > ,
252+ ) -> Result < Self , Error > {
253+ match result {
254+ Ok ( rsp) => Ok ( BytesResponse :: from ( rsp) ) ,
255+ Err ( e) => Err ( Error :: Other ( Box :: new ( e) ) ) ,
256+ }
257+ }
258+
257259 pub ( crate ) async fn body ( mut self ) -> Result < Bytes , Box < dyn StdError + Send + Sync + ' static > > {
258260 self . body . into_bytes ( ) . await
259261 }
0 commit comments