@@ -105,23 +105,51 @@ pub mod hyper {
105
105
106
106
use super :: { async_trait, Bytes , HttpClient , HttpError , Request , Response } ;
107
107
use http:: HeaderValue ;
108
- use http_body_util:: BodyExt ;
109
- use hyper:: body:: Body ;
108
+ use http_body_util:: { BodyExt , Full } ;
109
+ use hyper:: body:: { Body as HttpBody , Frame } ;
110
110
use hyper_util:: client:: legacy:: { connect:: Connect , Client } ;
111
- use std:: error :: Error ;
111
+ use std:: convert :: Infallible ;
112
112
use std:: fmt:: Debug ;
113
+ use std:: pin:: Pin ;
114
+ use std:: task:: { self , Poll } ;
113
115
use std:: time:: Duration ;
114
116
use tokio:: time;
115
117
118
+ pub struct Body ( Full < Bytes > ) ;
119
+
120
+ impl HttpBody for Body {
121
+ type Data = Bytes ;
122
+ type Error = Infallible ;
123
+
124
+ #[ inline]
125
+ fn poll_frame (
126
+ self : Pin < & mut Self > ,
127
+ cx : & mut task:: Context < ' _ > ,
128
+ ) -> Poll < Option < Result < Frame < Self :: Data > , Self :: Error > > > {
129
+ let inner_body = unsafe { self . map_unchecked_mut ( |b| & mut b. 0 ) } ;
130
+ inner_body. poll_frame ( cx)
131
+ }
132
+
133
+ #[ inline]
134
+ fn is_end_stream ( & self ) -> bool {
135
+ self . 0 . is_end_stream ( )
136
+ }
137
+
138
+ #[ inline]
139
+ fn size_hint ( & self ) -> hyper:: body:: SizeHint {
140
+ self . 0 . size_hint ( )
141
+ }
142
+ }
143
+
116
144
#[ derive( Debug , Clone ) ]
117
- pub struct HyperClient < C , B > {
118
- inner : Client < C , B > ,
145
+ pub struct HyperClient < C > {
146
+ inner : Client < C , Body > ,
119
147
timeout : Duration ,
120
148
authorization : Option < HeaderValue > ,
121
149
}
122
150
123
- impl < C , B > HyperClient < C , B > {
124
- pub fn new_with_timeout ( inner : Client < C , B > , timeout : Duration ) -> Self {
151
+ impl < C > HyperClient < C > {
152
+ pub fn new_with_timeout ( inner : Client < C , Body > , timeout : Duration ) -> Self {
125
153
Self {
126
154
inner,
127
155
timeout,
@@ -130,7 +158,7 @@ pub mod hyper {
130
158
}
131
159
132
160
pub fn new_with_timeout_and_authorization_header (
133
- inner : Client < C , B > ,
161
+ inner : Client < C , Body > ,
134
162
timeout : Duration ,
135
163
authorization : HeaderValue ,
136
164
) -> Self {
@@ -143,16 +171,13 @@ pub mod hyper {
143
171
}
144
172
145
173
#[ async_trait]
146
- impl < C , B > HttpClient for HyperClient < C , B >
174
+ impl < C > HttpClient for HyperClient < C >
147
175
where
148
176
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 > > ,
152
177
{
153
178
async fn send ( & self , request : Request < Vec < u8 > > ) -> Result < Response < Bytes > , HttpError > {
154
179
let ( parts, body) = request. into_parts ( ) ;
155
- let mut request = Request :: from_parts ( parts, B :: from ( body) ) ;
180
+ let mut request = Request :: from_parts ( parts, Body ( Full :: from ( body) ) ) ;
156
181
if let Some ( ref authorization) = self . authorization {
157
182
request
158
183
. headers_mut ( )
0 commit comments