Skip to content

Commit

Permalink
chore(http): rename http/version to http/variant (#3555)
Browse files Browse the repository at this point in the history
The proxy::http::Version type is very similar to the HTTP crate's Version type,
though it is more constrained so that the proxy may exhaustively match on it.
This change renames the module to http::variant to avoid confusion with the HTTP
crate's Version type.

To disambiguate the HTTP version type, the proxy::http::Version type is renamed
to proxy::http::Variant.
  • Loading branch information
olix0r authored Jan 22, 2025
1 parent de25333 commit d436b93
Show file tree
Hide file tree
Showing 37 changed files with 147 additions and 145 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ dependencies = [
"linkerd-duplex",
"linkerd-error",
"linkerd-http-box",
"linkerd-http-version",
"linkerd-http-variant",
"linkerd-io",
"linkerd-stack",
"pin-project",
Expand All @@ -1866,7 +1866,7 @@ dependencies = [
]

[[package]]
name = "linkerd-http-version"
name = "linkerd-http-variant"
version = "0.1.0"
dependencies = [
"http",
Expand Down Expand Up @@ -2241,7 +2241,7 @@ dependencies = [
"linkerd-http-retain",
"linkerd-http-stream-timeouts",
"linkerd-http-upgrade",
"linkerd-http-version",
"linkerd-http-variant",
"linkerd-io",
"linkerd-proxy-balance",
"linkerd-stack",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ members = [
"linkerd/http/route",
"linkerd/http/stream-timeouts",
"linkerd/http/upgrade",
"linkerd/http/version",
"linkerd/http/variant",
"linkerd/identity",
"linkerd/idle-cache",
"linkerd/io",
Expand Down
12 changes: 6 additions & 6 deletions linkerd/app/admin/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Tcp {
#[derive(Clone, Debug)]
struct Http {
tcp: Tcp,
version: http::Version,
version: http::Variant,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Config {
}))
.push_filter(
|(http, tcp): (
Result<Option<http::Version>, detect::DetectTimeoutError<_>>,
Result<Option<http::Variant>, detect::DetectTimeoutError<_>>,
Tcp,
)| {
match http {
Expand All @@ -150,10 +150,10 @@ impl Config {
// confused/stale.
Err(_timeout) => {
let version = match tcp.tls {
tls::ConditionalServerTls::None(_) => http::Version::Http1,
tls::ConditionalServerTls::None(_) => http::Variant::Http1,
tls::ConditionalServerTls::Some(tls::ServerTls::Established {
..
}) => http::Version::H2,
}) => http::Variant::H2,
tls::ConditionalServerTls::Some(tls::ServerTls::Passthru {
sni,
}) => {
Expand Down Expand Up @@ -219,8 +219,8 @@ impl Param<transport::labels::Key> for Tcp {

// === impl Http ===

impl Param<http::Version> for Http {
fn param(&self) -> http::Version {
impl Param<http::Variant> for Http {
fn param(&self) -> http::Variant {
self.version
}
}
Expand Down
10 changes: 5 additions & 5 deletions linkerd/app/gateway/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(crate) use self::gateway::NewHttpGateway;
pub struct Target<T = ()> {
addr: GatewayAddr,
routes: watch::Receiver<outbound::http::Routes>,
version: http::Version,
version: http::Variant,
parent: T,
}

Expand Down Expand Up @@ -74,7 +74,7 @@ impl Gateway {
T: svc::Param<tls::ClientId>,
T: svc::Param<inbound::policy::AllowPolicy>,
T: svc::Param<Option<watch::Receiver<profiles::Profile>>>,
T: svc::Param<http::Version>,
T: svc::Param<http::Variant>,
T: svc::Param<http::normalize_uri::DefaultAuthority>,
T: Clone + Send + Sync + Unpin + 'static,
// Endpoint resolution.
Expand Down Expand Up @@ -164,7 +164,7 @@ fn mk_routes(profile: &profiles::Profile) -> Option<outbound::http::Routes> {

impl<B, T: Clone> svc::router::SelectRoute<http::Request<B>> for ByRequestVersion<T> {
type Key = Target<T>;
type Error = http::version::Unsupported;
type Error = http::UnsupportedVariant;

fn select(&self, req: &http::Request<B>) -> Result<Self::Key, Self::Error> {
let mut t = self.0.clone();
Expand Down Expand Up @@ -192,8 +192,8 @@ impl<T> svc::Param<GatewayAddr> for Target<T> {
}
}

impl<T> svc::Param<http::Version> for Target<T> {
fn param(&self) -> http::Version {
impl<T> svc::Param<http::Variant> for Target<T> {
fn param(&self) -> http::Variant {
self.version
}
}
Expand Down
6 changes: 3 additions & 3 deletions linkerd/app/gateway/src/http/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ async fn upgraded_request_remains_relative_form() {
}
}

impl svc::Param<http::Version> for Target {
fn param(&self) -> http::Version {
http::Version::H2
impl svc::Param<http::Variant> for Target {
fn param(&self) -> http::Variant {
http::Variant::H2
}
}

Expand Down
10 changes: 5 additions & 5 deletions linkerd/app/gateway/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio::sync::watch;
/// Target for HTTP stacks.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Http<T> {
version: http::Version,
version: http::Variant,
parent: outbound::Discovery<T>,
}

Expand Down Expand Up @@ -61,8 +61,8 @@ impl Gateway {
|parent: outbound::Discovery<T>| -> Result<_, GatewayDomainInvalid> {
if let Some(proto) = (*parent).param() {
let version = match proto {
SessionProtocol::Http1 => http::Version::Http1,
SessionProtocol::Http2 => http::Version::H2,
SessionProtocol::Http1 => http::Variant::Http1,
SessionProtocol::Http2 => http::Variant::H2,
};
return Ok(svc::Either::A(Http { parent, version }));
}
Expand Down Expand Up @@ -154,8 +154,8 @@ impl<T> std::ops::Deref for Http<T> {
}
}

impl<T> svc::Param<http::Version> for Http<T> {
fn param(&self) -> http::Version {
impl<T> svc::Param<http::Variant> for Http<T> {
fn param(&self) -> http::Variant {
self.version
}
}
Expand Down
12 changes: 6 additions & 6 deletions linkerd/app/inbound/src/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) struct Forward {
#[derive(Clone, Debug)]
pub(crate) struct Http {
tls: Tls,
http: http::Version,
http: http::Variant,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Inbound<svc::ArcNewTcp<Http, io::BoxedIo>> {
// proxy handle the protocol error if we're in an edge case.
info!(%timeout, "Handling connection as HTTP/1 due to policy");
Ok(svc::Either::A(Http {
http: http::Version::Http1,
http: http::Variant::Http1,
tls,
}))
}
Expand Down Expand Up @@ -174,8 +174,8 @@ impl Inbound<svc::ArcNewTcp<Http, io::BoxedIo>> {
}
// Unmeshed services don't use protocol upgrading, so we can use the
// hint without further detection.
Protocol::Http1 { .. } => http::Version::Http1,
Protocol::Http2 { .. } | Protocol::Grpc { .. } => http::Version::H2,
Protocol::Http1 { .. } => http::Variant::Http1,
Protocol::Http2 { .. } | Protocol::Grpc { .. } => http::Variant::H2,
_ => unreachable!("opaque protocols must not hit the HTTP stack"),
};
Ok(svc::Either::A(Http { http, tls }))
Expand Down Expand Up @@ -342,8 +342,8 @@ impl svc::ExtractParam<detect::Config<http::DetectHttp>, Detect> for ConfigureHt

// === impl Http ===

impl svc::Param<http::Version> for Http {
fn param(&self) -> http::Version {
impl svc::Param<http::Variant> for Http {
fn param(&self) -> http::Variant {
self.http
}
}
Expand Down
8 changes: 4 additions & 4 deletions linkerd/app/inbound/src/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ impl svc::Param<policy::AllowPolicy> for LocalHttp {
}
}

impl svc::Param<http::Version> for LocalHttp {
fn param(&self) -> http::Version {
impl svc::Param<http::Variant> for LocalHttp {
fn param(&self) -> http::Variant {
match self.protocol {
SessionProtocol::Http1 => http::Version::Http1,
SessionProtocol::Http2 => http::Version::H2,
SessionProtocol::Http1 => http::Variant::Http1,
SessionProtocol::Http2 => http::Variant::H2,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions linkerd/app/inbound/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ pub mod fuzz {
}

#[derive(Clone, Debug)]
struct Target(http::Version);
struct Target(http::Variant);

// === impl Target ===

impl Target {
const HTTP1: Self = Self(http::Version::Http1);
const HTTP1: Self = Self(http::Variant::Http1);

fn addr() -> SocketAddr {
([127, 0, 0, 1], 80).into()
Expand All @@ -192,8 +192,8 @@ pub mod fuzz {
}
}

impl svc::Param<http::Version> for Target {
fn param(&self) -> http::Version {
impl svc::Param<http::Variant> for Target {
fn param(&self) -> http::Variant {
self.0
}
}
Expand Down
8 changes: 4 additions & 4 deletions linkerd/app/inbound/src/http/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Logical {
/// The request's logical destination. Used for profile discovery.
logical: Option<NameAddr>,
addr: Remote<ServerAddr>,
http: http::Version,
http: http::Variant,
tls: tls::ConditionalServerTls,
permit: policy::HttpRoutePermit,
labels: tap::Labels,
Expand Down Expand Up @@ -69,7 +69,7 @@ struct LogicalError {
impl<C> Inbound<C> {
pub(crate) fn push_http_router<T, P>(self, profiles: P) -> Inbound<svc::ArcNewCloneHttp<T>>
where
T: Param<http::Version>
T: Param<http::Variant>
+ Param<Remote<ServerAddr>>
+ Param<Remote<ClientAddr>>
+ Param<tls::ConditionalServerTls>
Expand Down Expand Up @@ -105,8 +105,8 @@ impl<C> Inbound<C> {
addr: t.addr,
permit: t.permit,
params: match t.http {
http::Version::Http1 => http::client::Params::Http1(h1_params),
http::Version::H2 => http::client::Params::H2(h2_params.clone())
http::Variant::Http1 => http::client::Params::Http1(h1_params),
http::Variant::H2 => http::client::Params::H2(h2_params.clone())
},
}
})
Expand Down
6 changes: 3 additions & 3 deletions linkerd/app/inbound/src/http/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::set_identity_header::NewSetIdentityHeader;
use crate::{policy, Inbound};
pub use linkerd_app_core::proxy::http::{normalize_uri, Version};
pub use linkerd_app_core::proxy::http::{normalize_uri, Variant};
use linkerd_app_core::{
config::ProxyConfig,
errors, http_tracing, io,
Expand Down Expand Up @@ -31,7 +31,7 @@ impl<H> Inbound<H> {
pub fn push_http_server<T, HSvc>(self) -> Inbound<svc::ArcNewCloneHttp<T>>
where
// Connection target.
T: Param<Version>
T: Param<Variant>
+ Param<normalize_uri::DefaultAuthority>
+ Param<tls::ConditionalServerTls>
+ Param<ServerLabel>
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<H> Inbound<H> {
pub fn push_http_tcp_server<T, I, HSvc>(self) -> Inbound<svc::ArcNewTcp<T, I>>
where
// Connection target.
T: Param<Version>,
T: Param<Variant>,
T: Clone + Send + Unpin + 'static,
// Server-side socket.
I: io::AsyncRead + io::AsyncWrite + io::PeerAddr + Send + Unpin + 'static,
Expand Down
14 changes: 7 additions & 7 deletions linkerd/app/inbound/src/http/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ fn connect_timeout() -> Box<dyn FnMut(Remote<ServerAddr>) -> ConnectFuture + Sen
}

#[derive(Clone, Debug)]
struct Target(http::Version, tls::ConditionalServerTls);
struct Target(http::Variant, tls::ConditionalServerTls);

#[track_caller]
fn check_error_header(hdrs: &::http::HeaderMap, expected: &str) {
Expand All @@ -782,17 +782,17 @@ fn check_error_header(hdrs: &::http::HeaderMap, expected: &str) {

impl Target {
const UNMESHED_HTTP1: Self = Self(
http::Version::Http1,
http::Variant::Http1,
tls::ConditionalServerTls::None(tls::NoServerTls::NoClientHello),
);
const UNMESHED_H2: Self = Self(
http::Version::H2,
http::Variant::H2,
tls::ConditionalServerTls::None(tls::NoServerTls::NoClientHello),
);

fn meshed_http1() -> Self {
Self(
http::Version::Http1,
http::Variant::Http1,
tls::ConditionalServerTls::Some(tls::ServerTls::Established {
client_id: Some(tls::ClientId(
"foosa.barns.serviceaccount.identity.linkerd.cluster.local"
Expand All @@ -806,7 +806,7 @@ impl Target {

fn meshed_h2() -> Self {
Self(
http::Version::H2,
http::Variant::H2,
tls::ConditionalServerTls::Some(tls::ServerTls::Established {
client_id: Some(tls::ClientId(
"foosa.barns.serviceaccount.identity.linkerd.cluster.local"
Expand Down Expand Up @@ -841,8 +841,8 @@ impl svc::Param<Remote<ClientAddr>> for Target {
}
}

impl svc::Param<http::Version> for Target {
fn param(&self) -> http::Version {
impl svc::Param<http::Variant> for Target {
fn param(&self) -> http::Variant {
self.0
}
}
Expand Down
8 changes: 4 additions & 4 deletions linkerd/app/outbound/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<T> Outbound<svc::ArcNewHttp<concrete::Endpoint<logical::Concrete<Http<T>>>>
pub fn push_http_cached<R>(self, resolve: R) -> Outbound<svc::ArcNewCloneHttp<T>>
where
// Logical HTTP target.
T: svc::Param<http::Version>,
T: svc::Param<http::Variant>,
T: svc::Param<watch::Receiver<Routes>>,
T: Clone + Debug + PartialEq + Eq + Hash + Send + Sync + 'static,
// Endpoint resolution.
Expand All @@ -109,11 +109,11 @@ impl<T> Outbound<svc::ArcNewHttp<concrete::Endpoint<logical::Concrete<Http<T>>>>

// === impl Http ===

impl<T> svc::Param<http::Version> for Http<T>
impl<T> svc::Param<http::Variant> for Http<T>
where
T: svc::Param<http::Version>,
T: svc::Param<http::Variant>,
{
fn param(&self) -> http::Version {
fn param(&self) -> http::Variant {
self.0.param()
}
}
Expand Down
Loading

0 comments on commit d436b93

Please sign in to comment.