@@ -105,21 +105,23 @@ pub mod hyper {
105105
106106 use super :: { async_trait, Bytes , HttpClient , HttpError , Request , Response } ;
107107 use http:: HeaderValue ;
108- use hyper:: client:: connect:: Connect ;
109- use hyper:: Client ;
108+ use hyper:: body:: Body ;
109+ use hyper_util:: client:: legacy:: { connect:: Connect , Client } ;
110+ use http_body_util:: BodyExt ;
111+ use std:: error:: Error ;
110112 use std:: fmt:: Debug ;
111113 use std:: time:: Duration ;
112114 use tokio:: time;
113115
114116 #[ derive( Debug , Clone ) ]
115- pub struct HyperClient < C > {
116- inner : Client < C > ,
117+ pub struct HyperClient < C , B > {
118+ inner : Client < C , B > ,
117119 timeout : Duration ,
118120 authorization : Option < HeaderValue > ,
119121 }
120122
121- impl < C > HyperClient < C > {
122- pub fn new_with_timeout ( inner : Client < C > , timeout : Duration ) -> Self {
123+ impl < C , B > HyperClient < C , B > {
124+ pub fn new_with_timeout ( inner : Client < C , B > , timeout : Duration ) -> Self {
123125 Self {
124126 inner,
125127 timeout,
@@ -128,7 +130,7 @@ pub mod hyper {
128130 }
129131
130132 pub fn new_with_timeout_and_authorization_header (
131- inner : Client < C > ,
133+ inner : Client < C , B > ,
132134 timeout : Duration ,
133135 authorization : HeaderValue ,
134136 ) -> Self {
@@ -141,23 +143,27 @@ pub mod hyper {
141143 }
142144
143145 #[ async_trait]
144- impl < C > HttpClient for HyperClient < C >
146+ impl < C , B > HttpClient for HyperClient < C , B >
145147 where
146148 C : Connect + Send + Sync + Clone + Debug + ' static ,
149+ B : From < Vec < u8 > > + Body + Send + Sync + Debug + Unpin + ' static ,
150+ <B as Body >:: Data : Send ,
151+ <B as Body >:: Error : Into < Box < dyn Error + Send + Sync > > ,
147152 {
148153 async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
149154 let ( parts, body) = request. into_parts ( ) ;
150- let mut request = Request :: from_parts ( parts, body. into ( ) ) ;
155+ let mut request: Request < B > = Request :: from_parts ( parts, body. into ( ) ) ;
151156 if let Some ( ref authorization) = self . authorization {
152157 request
153158 . headers_mut ( )
154159 . insert ( http:: header:: AUTHORIZATION , authorization. clone ( ) ) ;
155160 }
156161 let mut response = time:: timeout ( self . timeout , self . inner . request ( request) ) . await ??;
157162 let headers = std:: mem:: take ( response. headers_mut ( ) ) ;
163+
158164 let mut http_response = Response :: builder ( )
159165 . status ( response. status ( ) )
160- . body ( hyper :: body :: to_bytes ( response. into_body ( ) ) . await ?) ?;
166+ . body ( response. into_body ( ) . collect ( ) . await ?. to_bytes ( ) ) ?;
161167 * http_response. headers_mut ( ) = headers;
162168
163169 Ok ( http_response. error_for_status ( ) ?)
0 commit comments