Skip to content

Commit e49fc6c

Browse files
committed
refactor(proxy/http): http/1 client is a Service<T>
this is a small mechanical refactor to the http/1 client. our http/2 and "orig_proto" clients are tower services. our http/1 client, on the other hand, exposes a concrete inherent method `request`. to be consistent, this changes our http client to treat this http/1 client as a service as well. Signed-off-by: katelyn martin <kate@buoyant.io>
1 parent d35e12f commit e49fc6c

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

linkerd/proxy/http/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ where
136136
match self {
137137
Self::H2(ref mut svc) => svc.poll_ready(cx).map_err(Into::into),
138138
Self::OrigProtoUpgrade(ref mut svc) => svc.poll_ready(cx),
139-
Self::Http1(_) => Poll::Ready(Ok(())),
139+
Self::Http1(ref mut svc) => svc.poll_ready(cx),
140140
}
141141
}
142142

@@ -155,7 +155,7 @@ where
155155
debug!(headers = ?req.headers());
156156

157157
match self {
158-
Self::Http1(ref mut h1) => h1.request(req),
158+
Self::Http1(ref mut svc) => svc.call(req),
159159
Self::OrigProtoUpgrade(ref mut svc) => svc.call(req),
160160
Self::H2(ref mut svc) => Box::pin(
161161
svc.call(req)

linkerd/proxy/http/src/h1.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<C: Clone, T: Clone, B> Clone for Client<C, T, B> {
6161

6262
type RspFuture = Pin<Box<dyn Future<Output = Result<http::Response<BoxBody>>> + Send + 'static>>;
6363

64-
impl<C, T, B> Client<C, T, B>
64+
impl<C, T, B> tower::Service<http::Request<B>> for Client<C, T, B>
6565
where
6666
T: Clone + Send + Sync + 'static,
6767
C: MakeConnection<(crate::Variant, T)> + Clone + Send + Sync + 'static,
@@ -71,7 +71,15 @@ where
7171
B::Data: Send,
7272
B::Error: Into<Error> + Send + Sync,
7373
{
74-
pub(crate) fn request(&mut self, mut req: http::Request<B>) -> RspFuture {
74+
type Response = http::Response<BoxBody>;
75+
type Error = Error;
76+
type Future = RspFuture;
77+
78+
fn poll_ready(&mut self, _: &mut std::task::Context<'_>) -> std::task::Poll<Result<()>> {
79+
std::task::Poll::Ready(Ok(()))
80+
}
81+
82+
fn call(&mut self, mut req: http::Request<B>) -> RspFuture {
7583
// Marked by `upgrade`.
7684
let upgrade = req.extensions_mut().remove::<Http11Upgrade>();
7785
let is_http_connect = req.method() == http::Method::CONNECT;

linkerd/proxy/http/src/orig_proto.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ where
6767

6868
#[inline]
6969
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
70-
self.h2.poll_ready(cx).map_err(downgrade_h2_error)
70+
let Self { http1, h2 } = self;
71+
72+
match http1.poll_ready(cx) {
73+
Poll::Ready(Ok(())) => {}
74+
poll => return poll,
75+
}
76+
77+
h2.poll_ready(cx).map_err(downgrade_h2_error)
7178
}
7279

7380
fn call(&mut self, mut req: http::Request<B>) -> Self::Future {
@@ -78,7 +85,7 @@ where
7885
.is_some()
7986
{
8087
debug!("Skipping orig-proto upgrade due to HTTP/1.1 upgrade");
81-
return Box::pin(self.http1.request(req).map_ok(|rsp| rsp.map(BoxBody::new)));
88+
return Box::pin(self.http1.call(req).map_ok(|rsp| rsp.map(BoxBody::new)));
8289
}
8390

8491
let orig_version = req.version();

0 commit comments

Comments
 (0)