tower_hyper/client/
connection.rs1use super::background::Handle;
2use super::ResponseFuture;
3use crate::body::{Body, LiftBody};
4use futures::Poll;
5use http::{Request, Response};
6use http_body::Body as HttpBody;
7use hyper::client::conn;
8use tower_service::Service;
9
10#[derive(Debug)]
16pub struct Connection<B>
17where
18 B: HttpBody,
19{
20 sender: conn::SendRequest<LiftBody<B>>,
21 handle: Handle,
22}
23
24impl<B> Connection<B>
25where
26 B: HttpBody,
27{
28 pub(super) fn new(sender: conn::SendRequest<LiftBody<B>>, handle: Handle) -> Self {
29 Connection { sender, handle }
30 }
31}
32
33impl<B> Service<Request<B>> for Connection<B>
34where
35 B: HttpBody + Send + 'static,
36 B::Data: Send,
37 B::Error: Into<crate::Error>,
38{
39 type Response = Response<Body>;
40 type Error = hyper::Error;
41 type Future = ResponseFuture<conn::ResponseFuture>;
42
43 fn poll_ready(&mut self) -> Poll<(), Self::Error> {
44 if let Some(e) = self.handle.get_error() {
45 return Err(e);
46 }
47 self.sender.poll_ready()
48 }
49
50 fn call(&mut self, req: Request<B>) -> Self::Future {
51 let inner = self.sender.send_request(req.map(LiftBody::from));
52 ResponseFuture { inner }
53 }
54}