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