@@ -29,8 +29,8 @@ fn into_base_path(input: impl TryInto<Uri, Error=hyper::http::uri::InvalidUri>,
29
29
/// A client that implements the API by making HTTP calls out to a server.
30
30
pub struct Client<S , C > where
31
31
S: Service<
32
- (Request<Body >, C),
33
- Response=Response<Body >> + Clone + Sync + Send + 'static,
32
+ (Request<BoxBody < Bytes, Infallible > >, C),
33
+ Response=Response<Incoming >> + Clone + Sync + Send + 'static,
34
34
S::Future: Send + 'static,
35
35
S::Error: Into<crate::ServiceError > + fmt::Display,
36
36
C: Clone + Send + Sync + 'static
@@ -47,8 +47,8 @@ pub struct Client<S, C> where
47
47
48
48
impl<S , C > fmt::Debug for Client<S , C > where
49
49
S: Service<
50
- (Request<Body >, C),
51
- Response=Response<Body >> + Clone + Sync + Send + 'static,
50
+ (Request<BoxBody < Bytes, Infallible > >, C),
51
+ Response=Response<Incoming >> + Clone + Sync + Send + 'static,
52
52
S::Future: Send + 'static,
53
53
S::Error: Into<crate::ServiceError > + fmt::Display,
54
54
C: Clone + Send + Sync + 'static
@@ -60,8 +60,8 @@ impl<S, C> fmt::Debug for Client<S, C> where
60
60
61
61
impl<S, C> Clone for Client<S, C> where
62
62
S: Service<
63
- (Request<Body >, C),
64
- Response=Response<Body >> + Clone + Sync + Send + ' static,
63
+ (Request<BoxBody<Bytes, Infallible> >, C),
64
+ Response=Response<Incoming >> + Clone + Sync + Send + ' static,
65
65
S::Future: Send + ' static,
66
66
S::Error: Into<crate::ServiceError> + fmt::Display,
67
67
C: Clone + Send + Sync + ' static
@@ -75,8 +75,19 @@ impl<S, C> Clone for Client<S, C> where
75
75
}
76
76
}
77
77
78
- impl<Connector , C > Client<DropContextService <hyper::client::Client <Connector, Body >, C>, C> where
79
- Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static,
78
+ impl<Connector , C > Client<
79
+ DropContextService<
80
+ hyper_util::service::TowerToHyperService<
81
+ hyper_util::client::legacy::Client<
82
+ Connector,
83
+ BoxBody<Bytes , Infallible >
84
+ >
85
+ >,
86
+ C
87
+ >,
88
+ C
89
+ > where
90
+ Connector: hyper_util::client::legacy::connect::Connect + Clone + Send + Sync + 'static,
80
91
C: Clone + Send + Sync + 'static,
81
92
{
82
93
/// Create a client with a custom implementation of hyper::client::Connect.
@@ -99,8 +110,8 @@ impl<Connector, C> Client<DropContextService<hyper::client::Client<Connector, Bo
99
110
connector: Connector,
100
111
) -> Result<Self, ClientInitError>
101
112
{
102
- let client_service = hyper ::client::Client::builder().build(connector);
103
- let client_service = DropContextService::new(client_service);
113
+ let client_service = hyper_util ::client::legacy:: Client::builder(hyper_util::rt::TokioExecutor::new() ).build(connector);
114
+ let client_service = DropContextService::new(hyper_util::service::TowerToHyperService::new( client_service) );
104
115
105
116
Ok(Self {
106
117
client_service,
@@ -112,26 +123,19 @@ impl<Connector, C> Client<DropContextService<hyper::client::Client<Connector, Bo
112
123
113
124
#[derive(Debug, Clone)]
114
125
pub enum HyperClient {
115
- Http(hyper ::client::Client<hyper ::client::HttpConnector, Body >),
116
- Https(hyper ::client::Client<HttpsConnector, Body >),
126
+ Http(hyper_util ::client::legacy:: Client<hyper_util ::client::legacy::connect:: HttpConnector, BoxBody<Bytes, Infallible> >),
127
+ Https(hyper_util ::client::legacy:: Client<HttpsConnector, BoxBody<Bytes, Infallible> >),
117
128
}
118
129
119
- impl Service<Request<Body>> for HyperClient {
120
- type Response = Response<Body>;
121
- type Error = hyper::Error;
122
- type Future = hyper::client::ResponseFuture;
123
-
124
- fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
125
- match self {
126
- HyperClient::Http(client) => client.poll_ready(cx),
127
- HyperClient::Https(client) => client.poll_ready(cx),
128
- }
129
- }
130
+ impl Service<Request<BoxBody<Bytes, Infallible>>> for HyperClient {
131
+ type Response = Response<Incoming>;
132
+ type Error = hyper_util::client::legacy::Error;
133
+ type Future = hyper_util::client::legacy::ResponseFuture;
130
134
131
- fn call(&mut self, req: Request<Body >) -> Self::Future {
135
+ fn call(&self, req: Request<BoxBody<Bytes, Infallible> >) -> Self::Future {
132
136
match self {
133
- HyperClient::Http(client) => client.call (req),
134
- HyperClient::Https(client) => client.call (req)
137
+ HyperClient::Http(client) => client.request (req),
138
+ HyperClient::Https(client) => client.request (req)
135
139
}
136
140
}
137
141
}
@@ -155,13 +159,13 @@ impl<C> Client<DropContextService<HyperClient, C>, C> where
155
159
156
160
let client_service = match scheme.as_str() {
157
161
" http" => {
158
- HyperClient::Http(hyper ::client::Client::builder().build(connector.build()))
162
+ HyperClient::Http(hyper_util ::client::legacy:: Client::builder(hyper_util::rt::TokioExecutor::new() ).build(connector.build()))
159
163
} ,
160
164
"https" => {
161
165
let connector = connector.https()
162
166
.build()
163
167
.map_err(ClientInitError::SslError)?;
164
- HyperClient::Https(hyper ::client::Client::builder().build(connector))
168
+ HyperClient::Https(hyper_util ::client::legacy:: Client::builder(hyper_util::rt::TokioExecutor::new() ).build(connector))
165
169
} ,
166
170
_ => {
167
171
return Err(ClientInitError::InvalidScheme);
@@ -178,7 +182,18 @@ impl<C> Client<DropContextService<HyperClient, C>, C> where
178
182
}
179
183
}
180
184
181
- impl<C > Client<DropContextService <hyper::client::Client <hyper::client::HttpConnector, Body >, C>, C> where
185
+ impl<C > Client<
186
+ DropContextService<
187
+ hyper_util::service::TowerToHyperService<
188
+ hyper_util::client::legacy::Client<
189
+ HttpsConnector,
190
+ BoxBody<Bytes , Infallible >
191
+ >
192
+ >,
193
+ C
194
+ >,
195
+ C
196
+ > where
182
197
C: Clone + Send + Sync + 'static
183
198
{
184
199
/// Create an HTTP client.
@@ -200,7 +215,18 @@ type HttpsConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>;
200
215
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
201
216
type HttpsConnector = hyper_openssl::HttpsConnector<hyper::client::HttpConnector >;
202
217
203
- impl<C > Client<DropContextService <hyper::client::Client <HttpsConnector, Body >, C>, C> where
218
+ impl<C > Client<
219
+ DropContextService<
220
+ hyper_util::service::TowerToHyperService<
221
+ hyper_util::client::legacy::Client<
222
+ HttpsConnector,
223
+ BoxBody<Bytes , Infallible >
224
+ >
225
+ >,
226
+ C
227
+ >,
228
+ C
229
+ > where
204
230
C: Clone + Send + Sync + 'static
205
231
{
206
232
/// Create a client with a TLS connection to the server
@@ -268,8 +294,8 @@ impl<C> Client<DropContextService<hyper::client::Client<HttpsConnector, Body>, C
268
294
269
295
impl<S , C > Client<S , C > where
270
296
S: Service<
271
- (Request<Body >, C),
272
- Response=Response<Body >> + Clone + Sync + Send + 'static,
297
+ (Request<BoxBody < Bytes, Infallible > >, C),
298
+ Response=Response<Incoming >> + Clone + Sync + Send + 'static,
273
299
S::Future: Send + 'static,
274
300
S::Error: Into<crate::ServiceError > + fmt::Display,
275
301
C: Clone + Send + Sync + 'static
@@ -331,22 +357,19 @@ impl Error for ClientInitError {
331
357
}
332
358
}
333
359
360
+ fn body_from_string(s: String) -> BoxBody<Bytes, Infallible> {
361
+ BoxBody::new(Full::new(Bytes::from(s)))
362
+ }
363
+
334
364
#[async_trait]
335
365
impl<S, C> Api<C> for Client<S, C> where
336
366
S: Service<
337
- (Request<Body >, C),
338
- Response=Response<Body >> + Clone + Sync + Send + ' static,
367
+ (Request<BoxBody<Bytes, Infallible> >, C),
368
+ Response=Response<Incoming >> + Clone + Sync + Send + ' static,
339
369
S::Future: Send + ' static,
340
370
S::Error: Into<crate::ServiceError> + fmt::Display,
341
371
C: Has<XSpanIdString> {{#hasAuthMethods}}+ Has<Option<AuthData>>{{/hasAuthMethods}} + Clone + Send + Sync + ' static,
342
372
{
343
- fn poll_ready(&self, cx: &mut Context) -> Poll< Result< (), crate::ServiceError>> {
344
- match self.client_service.clone().poll_ready(cx) {
345
- Poll::Ready(Err(e)) => Poll::Ready(Err(e.into())),
346
- Poll::Ready(Ok(o)) => Poll::Ready(Ok(o)),
347
- Poll::Pending => Poll::Pending,
348
- }
349
- }
350
373
351
374
{{#apiInfo} }
352
375
{ {#apis} }
0 commit comments