@@ -29,8 +29,8 @@ fn into_base_path(input: impl TryInto<Uri, Error=hyper::http::uri::InvalidUri>,
2929/// A client that implements the API by making HTTP calls out to a server.
3030pub struct Client<S , C > where
3131 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,
3434 S::Future: Send + 'static,
3535 S::Error: Into<crate::ServiceError > + fmt::Display,
3636 C: Clone + Send + Sync + 'static
@@ -47,8 +47,8 @@ pub struct Client<S, C> where
4747
4848impl<S , C > fmt::Debug for Client<S , C > where
4949 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,
5252 S::Future: Send + 'static,
5353 S::Error: Into<crate::ServiceError > + fmt::Display,
5454 C: Clone + Send + Sync + 'static
@@ -60,8 +60,8 @@ impl<S, C> fmt::Debug for Client<S, C> where
6060
6161impl<S, C> Clone for Client<S, C> where
6262 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,
6565 S::Future: Send + ' static,
6666 S::Error: Into<crate::ServiceError> + fmt::Display,
6767 C: Clone + Send + Sync + ' static
@@ -75,8 +75,19 @@ impl<S, C> Clone for Client<S, C> where
7575 }
7676}
7777
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,
8091 C: Clone + Send + Sync + 'static,
8192{
8293 /// 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
99110 connector: Connector,
100111 ) -> Result<Self, ClientInitError>
101112 {
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) );
104115
105116 Ok(Self {
106117 client_service,
@@ -112,26 +123,19 @@ impl<Connector, C> Client<DropContextService<hyper::client::Client<Connector, Bo
112123
113124#[derive(Debug, Clone)]
114125pub 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> >),
117128}
118129
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;
130134
131- fn call(&mut self, req: Request<Body >) -> Self::Future {
135+ fn call(&self, req: Request<BoxBody<Bytes, Infallible> >) -> Self::Future {
132136 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)
135139 }
136140 }
137141}
@@ -155,13 +159,13 @@ impl<C> Client<DropContextService<HyperClient, C>, C> where
155159
156160 let client_service = match scheme.as_str() {
157161 " 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()))
159163 } ,
160164 "https" => {
161165 let connector = connector.https()
162166 .build()
163167 .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))
165169 } ,
166170 _ => {
167171 return Err(ClientInitError::InvalidScheme);
@@ -178,7 +182,18 @@ impl<C> Client<DropContextService<HyperClient, C>, C> where
178182 }
179183}
180184
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
182197 C: Clone + Send + Sync + 'static
183198{
184199 /// Create an HTTP client.
@@ -200,7 +215,18 @@ type HttpsConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>;
200215#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
201216type HttpsConnector = hyper_openssl::HttpsConnector<hyper::client::HttpConnector >;
202217
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
204230 C: Clone + Send + Sync + 'static
205231{
206232 /// Create a client with a TLS connection to the server
@@ -268,8 +294,8 @@ impl<C> Client<DropContextService<hyper::client::Client<HttpsConnector, Body>, C
268294
269295impl<S , C > Client<S , C > where
270296 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,
273299 S::Future: Send + 'static,
274300 S::Error: Into<crate::ServiceError > + fmt::Display,
275301 C: Clone + Send + Sync + 'static
@@ -331,22 +357,19 @@ impl Error for ClientInitError {
331357 }
332358}
333359
360+ fn body_from_string(s: String) -> BoxBody<Bytes, Infallible> {
361+ BoxBody::new(Full::new(Bytes::from(s)))
362+ }
363+
334364#[async_trait]
335365impl<S, C> Api<C> for Client<S, C> where
336366 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,
339369 S::Future: Send + ' static,
340370 S::Error: Into<crate::ServiceError> + fmt::Display,
341371 C: Has<XSpanIdString> {{#hasAuthMethods}}+ Has<Option<AuthData>>{{/hasAuthMethods}} + Clone + Send + Sync + ' static,
342372{
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- }
350373
351374{{#apiInfo} }
352375 { {#apis} }
0 commit comments