Replace `ResponseFuture` with `Box<dyn>` (#28)

This commit is contained in:
Daniel Bloom 2023-06-14 04:21:31 -07:00 committed by GitHub
parent a5ff6ff26e
commit 382aada615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -5,13 +5,14 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt; use std::fmt;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use base64::prelude::{Engine, BASE64_URL_SAFE_NO_PAD}; use base64::prelude::{Engine, BASE64_URL_SAFE_NO_PAD};
use hyper::client::connect::Connect; use hyper::client::connect::Connect;
#[cfg(feature = "hyper-rustls")] #[cfg(feature = "hyper-rustls")]
use hyper::client::HttpConnector; use hyper::client::HttpConnector;
use hyper::client::ResponseFuture;
use hyper::header::{CONTENT_TYPE, LOCATION}; use hyper::header::{CONTENT_TYPE, LOCATION};
use hyper::{Body, Method, Request, Response}; use hyper::{Body, Method, Request, Response};
use ring::digest::{digest, SHA256}; use ring::digest::{digest, SHA256};
@ -599,8 +600,11 @@ struct DefaultClient(hyper::Client<hyper_rustls::HttpsConnector<HttpConnector>>)
#[cfg(feature = "hyper-rustls")] #[cfg(feature = "hyper-rustls")]
impl HttpClient for DefaultClient { impl HttpClient for DefaultClient {
fn request(&self, req: Request<Body>) -> ResponseFuture { fn request(
self.0.request(req) &self,
req: Request<Body>,
) -> Pin<Box<dyn Future<Output = hyper::Result<Response<Body>>>>> {
Box::pin(self.0.request(req))
} }
} }
@ -623,15 +627,21 @@ impl Default for DefaultClient {
/// A HTTP client based on [`hyper::Client`] /// A HTTP client based on [`hyper::Client`]
pub trait HttpClient: Send + Sync + 'static { pub trait HttpClient: Send + Sync + 'static {
/// Send the given request and return the response /// Send the given request and return the response
fn request(&self, req: Request<Body>) -> ResponseFuture; fn request(
&self,
req: Request<Body>,
) -> Pin<Box<dyn Future<Output = hyper::Result<Response<Body>>>>>;
} }
impl<C> HttpClient for hyper::Client<C> impl<C> HttpClient for hyper::Client<C>
where where
C: Connect + Clone + Send + Sync + 'static, C: Connect + Clone + Send + Sync + 'static,
{ {
fn request(&self, req: Request<Body>) -> ResponseFuture { fn request(
<hyper::Client<C>>::request(self, req) &self,
req: Request<Body>,
) -> Pin<Box<dyn Future<Output = hyper::Result<Response<Body>>>>> {
Box::pin(<hyper::Client<C>>::request(self, req))
} }
} }