Skip to content

Commit e6aec6e

Browse files
authored
http: Parameterize authority overriding (#946)
The authority override module still uses a dedicated trait, `CanOverrideAuthority`. This change replaces this trait with a newtype, `AuthorityOverride`, which is provided via `Param`.
1 parent f7760af commit e6aec6e

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ impl Param<Option<SessionProtocol>> for Endpoint {
135135
}
136136
}
137137

138-
impl CanOverrideAuthority for Endpoint {
139-
fn override_authority(&self) -> Option<uri::Authority> {
140-
self.metadata.authority_override().cloned()
138+
impl Param<Option<AuthorityOverride>> for Endpoint {
139+
fn param(&self) -> Option<AuthorityOverride> {
140+
self.metadata
141+
.authority_override()
142+
.cloned()
143+
.map(AuthorityOverride)
141144
}
142145
}
143146

linkerd/proxy/http/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub use self::{
3030
glue::{HyperServerSvc, UpgradeBody},
3131
header_from_target::NewHeaderFromTarget,
3232
normalize_uri::{MarkAbsoluteForm, NewNormalizeUri},
33-
override_authority::{CanOverrideAuthority, NewOverrideAuthority},
33+
override_authority::{AuthorityOverride, NewOverrideAuthority},
3434
retain::Retain,
3535
server::NewServeHttp,
3636
timeout::MakeTimeoutLayer,

linkerd/proxy/http/src/override_authority.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use super::h1;
22
use http::{self, header::AsHeaderName, uri::Authority};
3-
use linkerd_stack::{layer, NewService};
3+
use linkerd_stack::{layer, NewService, Param};
44
use std::{
55
fmt,
66
sync::Arc,
77
task::{Context, Poll},
88
};
99
use tracing::debug;
1010

11-
pub trait CanOverrideAuthority {
12-
fn override_authority(&self) -> Option<Authority>;
13-
}
11+
#[derive(Clone, Debug)]
12+
pub struct AuthorityOverride(pub Authority);
1413

1514
#[derive(Clone, Debug)]
1615
pub struct NewOverrideAuthority<H, M> {
@@ -41,7 +40,7 @@ impl<H: Clone, N> NewOverrideAuthority<H, N> {
4140

4241
impl<H, T, M> NewService<T> for NewOverrideAuthority<H, M>
4342
where
44-
T: CanOverrideAuthority + Clone + Send + Sync + 'static,
43+
T: Param<Option<AuthorityOverride>>,
4544
M: NewService<T>,
4645
H: AsHeaderName + Clone,
4746
{
@@ -50,7 +49,7 @@ where
5049
#[inline]
5150
fn new_service(&mut self, t: T) -> Self::Service {
5251
OverrideAuthority {
53-
authority: t.override_authority(),
52+
authority: t.param().map(|AuthorityOverride(a)| a),
5453
headers_to_strip: self.headers_to_strip.clone(),
5554
inner: self.inner.new_service(t),
5655
}

0 commit comments

Comments
 (0)