Skip to content

Commit 6c57983

Browse files
authored
outbound: Decouple outbound HTTP server from logical target (#2249)
1 parent 8be0f9b commit 6c57983

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

linkerd/app/outbound/src/http/server.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
use super::{IdentityRequired, Logical, ProxyConnectionClose};
1+
use super::{IdentityRequired, ProxyConnectionClose};
22
use crate::{http, trace_labels, Outbound};
33
use linkerd_app_core::{
44
errors, http_tracing, io,
55
svc::{self, ExtractParam},
6-
transport::addrs::*,
7-
Addr, Error, Result,
6+
Error, Result,
87
};
98

109
#[derive(Copy, Clone, Debug)]
1110
pub(crate) struct ServerRescue {
1211
emit_headers: bool,
1312
}
1413

15-
#[derive(Copy, Clone, Debug)]
16-
struct Target<T>(T);
17-
1814
impl<N> Outbound<N> {
1915
/// Builds a [`svc::NewService`] stack that prepares HTTP requests to be
2016
/// proxied.
@@ -37,7 +33,8 @@ impl<N> Outbound<N> {
3733
>,
3834
>
3935
where
40-
T: svc::Param<Logical> + 'static,
36+
// Target
37+
T: svc::Param<http::normalize_uri::DefaultAuthority>,
4138
// HTTP outbound stack
4239
N: svc::NewService<T, Service = NSvc> + Clone + Send + Sync + 'static,
4340
NSvc: svc::Service<http::Request<http::BoxBody>, Response = http::Response<http::BoxBody>>,
@@ -80,14 +77,7 @@ impl<N> Outbound<N> {
8077
)
8178
// Convert origin form HTTP/1 URIs to absolute form for Hyper's
8279
// `Client`.
83-
.push(http::NewNormalizeUri::layer_via(|target: &T| {
84-
let addr = match target.param() {
85-
Logical::Route(addr, _) => Addr::from(addr),
86-
Logical::Forward(Remote(ServerAddr(addr)), _) => Addr::from(addr),
87-
};
88-
89-
http::normalize_uri::DefaultAuthority(Some(addr.to_http_authority()))
90-
}))
80+
.push(http::NewNormalizeUri::layer())
9181
// Record when a HTTP/1 URI originated in absolute form
9282
.push_on_service(http::normalize_uri::MarkAbsoluteForm::layer())
9383
.push(svc::ArcNewService::layer())

linkerd/app/outbound/src/ingress.rs

+9
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ impl svc::Param<http::Logical> for Http<http::Logical> {
258258
}
259259
}
260260

261+
impl svc::Param<http::normalize_uri::DefaultAuthority> for Http<http::Logical> {
262+
fn param(&self) -> http::normalize_uri::DefaultAuthority {
263+
http::normalize_uri::DefaultAuthority(match &self.parent {
264+
http::Logical::Route(addr, _) => Some(addr.as_http_authority()),
265+
http::Logical::Forward(..) => None,
266+
})
267+
}
268+
}
269+
261270
impl TryFrom<discover::Discovery<Http<RequestTarget>>> for Http<http::Logical> {
262271
type Error = ProfileRequired;
263272

linkerd/app/outbound/src/protocol.rs

+9
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,12 @@ where
132132
self.parent.param()
133133
}
134134
}
135+
136+
impl<T> svc::Param<http::normalize_uri::DefaultAuthority> for Http<T>
137+
where
138+
T: svc::Param<http::normalize_uri::DefaultAuthority>,
139+
{
140+
fn param(&self) -> http::normalize_uri::DefaultAuthority {
141+
self.parent.param()
142+
}
143+
}

linkerd/app/outbound/src/sidecar.rs

+9
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ impl svc::Param<Protocol> for Sidecar {
105105
}
106106
}
107107

108+
impl svc::Param<http::normalize_uri::DefaultAuthority> for Sidecar {
109+
fn param(&self) -> http::normalize_uri::DefaultAuthority {
110+
http::normalize_uri::DefaultAuthority(self.profile.as_ref().and_then(|p| {
111+
p.logical_addr()
112+
.map(|profiles::LogicalAddr(a)| a.as_http_authority())
113+
}))
114+
}
115+
}
116+
108117
impl svc::Param<http::Logical> for Sidecar {
109118
fn param(&self) -> http::Logical {
110119
if let Some(profile) = self.profile.clone() {

0 commit comments

Comments
 (0)