@@ -105,21 +105,23 @@ pub mod hyper {
105
105
106
106
use super :: { async_trait, Bytes , HttpClient , HttpError , Request , Response } ;
107
107
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 ;
110
112
use std:: fmt:: Debug ;
111
113
use std:: time:: Duration ;
112
114
use tokio:: time;
113
115
114
116
#[ derive( Debug , Clone ) ]
115
- pub struct HyperClient < C > {
116
- inner : Client < C > ,
117
+ pub struct HyperClient < C , B > {
118
+ inner : Client < C , B > ,
117
119
timeout : Duration ,
118
120
authorization : Option < HeaderValue > ,
119
121
}
120
122
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 {
123
125
Self {
124
126
inner,
125
127
timeout,
@@ -128,7 +130,7 @@ pub mod hyper {
128
130
}
129
131
130
132
pub fn new_with_timeout_and_authorization_header (
131
- inner : Client < C > ,
133
+ inner : Client < C , B > ,
132
134
timeout : Duration ,
133
135
authorization : HeaderValue ,
134
136
) -> Self {
@@ -141,23 +143,27 @@ pub mod hyper {
141
143
}
142
144
143
145
#[ async_trait]
144
- impl < C > HttpClient for HyperClient < C >
146
+ impl < C , B > HttpClient for HyperClient < C , B >
145
147
where
146
148
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 > > ,
147
152
{
148
153
async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
149
154
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 ( ) ) ;
151
156
if let Some ( ref authorization) = self . authorization {
152
157
request
153
158
. headers_mut ( )
154
159
. insert ( http:: header:: AUTHORIZATION , authorization. clone ( ) ) ;
155
160
}
156
161
let mut response = time:: timeout ( self . timeout , self . inner . request ( request) ) . await ??;
157
162
let headers = std:: mem:: take ( response. headers_mut ( ) ) ;
163
+
158
164
let mut http_response = Response :: builder ( )
159
165
. status ( response. status ( ) )
160
- . body ( hyper :: body :: to_bytes ( response. into_body ( ) ) . await ?) ?;
166
+ . body ( response. into_body ( ) . collect ( ) . await ?. to_bytes ( ) ) ?;
161
167
* http_response. headers_mut ( ) = headers;
162
168
163
169
Ok ( http_response. error_for_status ( ) ?)
0 commit comments