exc_core/transport/http/
channel.rs

1#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
2pub use https::HttpsChannel;
3
4#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
5/// Https channel.
6pub mod https {
7    use crate::ExchangeError;
8    use futures::{future::BoxFuture, FutureExt, TryFutureExt};
9    use http::{Request, Response};
10    use hyper::{client::HttpConnector, Body, Client};
11
12    cfg_if::cfg_if! {
13        if #[cfg(feature = "native-tls")] {
14            use hyper_tls::HttpsConnector;
15        } else if #[cfg(feature = "rustls-tls")] {
16            use hyper_rustls::HttpsConnector;
17        }
18    }
19
20    /// Https channel.
21    #[derive(Clone)]
22    pub struct HttpsChannel {
23        pub(crate) inner: Client<HttpsConnector<HttpConnector>>,
24    }
25
26    impl tower::Service<Request<Body>> for HttpsChannel {
27        type Response = Response<Body>;
28        type Error = ExchangeError;
29        type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
30
31        fn poll_ready(
32            &mut self,
33            cx: &mut std::task::Context<'_>,
34        ) -> std::task::Poll<Result<(), Self::Error>> {
35            self.inner.poll_ready(cx).map_err(ExchangeError::Http)
36        }
37
38        fn call(&mut self, req: Request<Body>) -> Self::Future {
39            tower::Service::call(&mut self.inner, req)
40                .map_err(ExchangeError::Http)
41                .boxed()
42        }
43    }
44}