1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::Transport;
use http::Request;

pub struct HyperTransport<C = ::hyper::client::HttpConnector, B = ::hyper::body::Body>(
    hyper::Client<C, B>,
);

impl<C, B> HyperTransport<C, B> {
    pub fn new(client: hyper::Client<C, B>) -> Self {
        Self(client)
    }

    pub fn into_inner(self) -> hyper::Client<C, B> {
        self.0
    }
}

impl<C, B> Into<HyperTransport<C, B>> for hyper::Client<C, B> {
    fn into(self) -> HyperTransport<C, B> {
        HyperTransport(self)
    }
}

impl Default for HyperTransport<::hyper::client::HttpConnector, ::hyper::body::Body> {
    fn default() -> Self {
        Self(hyper::Client::new())
    }
}

impl<C, B> Transport for HyperTransport<C, B>
where
    C: hyper::client::connect::Connect + Clone + Send + Sync + 'static,
    B: hyper::body::HttpBody + Send + 'static + From<Vec<u8>>,
    B::Data: Send,
    B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
{
    type Error = hyper::error::Error;
    type Output = hyper::client::ResponseFuture;
    type Body = hyper::body::Body;
    type Chunk = hyper::body::Bytes;

    fn roundtrip(&self, request: Request<Vec<u8>>) -> Self::Output {
        let (parts, body) = request.into_parts();
        let request = hyper::Request::from_parts(parts, body.into());
        self.0.request(request)
    }
}