|
| 1 | +use hyper::{Request, Response}; |
| 2 | +use tower::{Service, MakeService}; |
| 3 | + |
| 4 | +use super::connect::Connect; |
| 5 | +use super::pool; |
| 6 | + |
| 7 | +pub struct Client<M> { |
| 8 | + // Hi there. So, let's take a 0.14.x hyper::Client, and build up its layers |
| 9 | + // here. We don't need to fully expose the layers to start with, but that |
| 10 | + // is the end goal. |
| 11 | + // |
| 12 | + // Client = MakeSvcAsService< |
| 13 | + // SetHost< |
| 14 | + // Http1RequestTarget< |
| 15 | + // DelayedRelease< |
| 16 | + // ConnectingPool<C, P> |
| 17 | + // > |
| 18 | + // > |
| 19 | + // > |
| 20 | + // > |
| 21 | + make_svc: M, |
| 22 | +} |
| 23 | + |
| 24 | +// We might change this... :shrug: |
| 25 | +type PoolKey = hyper::Uri; |
| 26 | + |
| 27 | +struct ConnectingPool<C, P> { |
| 28 | + connector: C, |
| 29 | + pool: P, |
| 30 | +} |
| 31 | + |
| 32 | +struct PoolableSvc<S>(S); |
| 33 | + |
1 | 34 | /// A marker to identify what version a pooled connection is. |
2 | 35 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
3 | 36 | #[allow(dead_code)] |
4 | 37 | pub enum Ver { |
5 | 38 | Auto, |
6 | 39 | Http2, |
7 | 40 | } |
| 41 | + |
| 42 | +// ===== impl Client ===== |
| 43 | + |
| 44 | +impl<M, /*ReqBody, ResBody,*/ E> Client<M> |
| 45 | +where |
| 46 | + M: MakeService< |
| 47 | + hyper::Uri, |
| 48 | + Request<()>, |
| 49 | + Response = Response<()>, |
| 50 | + Error = E, |
| 51 | + MakeError = E, |
| 52 | + >, |
| 53 | + //M: Service<hyper::Uri, Error = E>, |
| 54 | + //M::Response: Service<Request<ReqBody>, Response = Response<ResBody>>, |
| 55 | +{ |
| 56 | + pub async fn request(&mut self, req: Request<()>) -> Result<Response<()>, E> { |
| 57 | + let mut svc = self.make_svc.make_service(req.uri().clone()).await?; |
| 58 | + svc.call(req).await |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +impl<M, /*ReqBody, ResBody,*/ E> Client<M> |
| 63 | +where |
| 64 | + M: MakeService< |
| 65 | + hyper::Uri, |
| 66 | + Request<()>, |
| 67 | + Response = Response<()>, |
| 68 | + Error = E, |
| 69 | + MakeError = E, |
| 70 | + >, |
| 71 | + //M: Service<hyper::Uri, Error = E>, |
| 72 | + //M::Response: Service<Request<ReqBody>, Response = Response<ResBody>>, |
| 73 | +{ |
| 74 | + |
| 75 | +} |
| 76 | + |
| 77 | +// ===== impl ConnectingPool ===== |
| 78 | + |
| 79 | +impl<C, P> ConnectingPool<C, P> |
| 80 | +where |
| 81 | + C: Connect, |
| 82 | + C::_Svc: Unpin + Send + 'static, |
| 83 | +{ |
| 84 | + async fn connection_for(&self, target: PoolKey) -> Result<pool::Pooled<PoolableSvc<C::_Svc>, PoolKey>, ()> { |
| 85 | + todo!() |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +impl<S> pool::Poolable for PoolableSvc<S> |
| 90 | +where |
| 91 | + S: Unpin + Send + 'static, |
| 92 | +{ |
| 93 | + fn is_open(&self) -> bool { |
| 94 | + /* |
| 95 | + match self.tx { |
| 96 | + PoolTx::Http1(ref tx) => tx.is_ready(), |
| 97 | + #[cfg(feature = "http2")] |
| 98 | + PoolTx::Http2(ref tx) => tx.is_ready(), |
| 99 | + } |
| 100 | + */ |
| 101 | + true |
| 102 | + } |
| 103 | + |
| 104 | + fn reserve(self) -> pool::Reservation<Self> { |
| 105 | + /* |
| 106 | + match self.tx { |
| 107 | + PoolTx::Http1(tx) => Reservation::Unique(PoolClient { |
| 108 | + conn_info: self.conn_info, |
| 109 | + tx: PoolTx::Http1(tx), |
| 110 | + }), |
| 111 | + #[cfg(feature = "http2")] |
| 112 | + PoolTx::Http2(tx) => { |
| 113 | + let b = PoolClient { |
| 114 | + conn_info: self.conn_info.clone(), |
| 115 | + tx: PoolTx::Http2(tx.clone()), |
| 116 | + }; |
| 117 | + let a = PoolClient { |
| 118 | + conn_info: self.conn_info, |
| 119 | + tx: PoolTx::Http2(tx), |
| 120 | + }; |
| 121 | + Reservation::Shared(a, b) |
| 122 | + } |
| 123 | + } |
| 124 | + */ |
| 125 | + pool::Reservation::Unique(self) |
| 126 | + } |
| 127 | + |
| 128 | + fn can_share(&self) -> bool { |
| 129 | + false |
| 130 | + //self.is_http2() |
| 131 | + } |
| 132 | +} |
0 commit comments