[core] Unix upstreams, tests first: unix:/path reaches both engines (edge address, Caddy dial), the path is strict, forward-auth never goes to a socket (red: not parsed yet)

This commit is contained in:
2026-11-10 21:02:41 +01:00
parent ffffa62999
commit 84c1c81906
3 changed files with 147 additions and 3 deletions
+23 -3
View File
@@ -64,11 +64,13 @@ impl Scheme {
}
}
/// Where the upstream host is: a DNS name or an IP literal (IPv6 without brackets).
/// Where the upstream host is: a DNS name, an IP literal (IPv6 without brackets), or a Unix
/// socket path (`unix:/abs/path`, plain HTTP; which socket a host may use is control's call).
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum UpstreamHost {
Name(String),
Ip(std::net::IpAddr),
Unix(String),
}
/// A validated upstream: scheme, host and explicit port. No path, query, fragment or userinfo.
@@ -81,26 +83,44 @@ pub struct Upstream {
}
impl Upstream {
/// `host:port` as used for dialing, with IPv6 in brackets.
/// `host:port` as used for dialing, with IPv6 in brackets; `unix:<path>` for a socket.
pub fn authority(&self) -> String {
match &self.host {
UpstreamHost::Name(n) => format!("{n}:{}", self.port),
UpstreamHost::Ip(std::net::IpAddr::V6(ip)) => format!("[{ip}]:{}", self.port),
UpstreamHost::Ip(ip) => format!("{ip}:{}", self.port),
UpstreamHost::Unix(p) => format!("unix:{p}"),
}
}
/// The host part for TLS SNI and certificate verification.
/// The host part for TLS SNI and certificate verification (empty for a socket, which is
/// always plain HTTP).
pub fn host_str(&self) -> String {
match &self.host {
UpstreamHost::Name(n) => n.clone(),
UpstreamHost::Ip(ip) => ip.to_string(),
UpstreamHost::Unix(_) => String::new(),
}
}
/// The socket path of a `unix:` upstream.
pub fn unix_path(&self) -> Option<&str> {
match &self.host {
UpstreamHost::Unix(p) => Some(p),
_ => None,
}
}
pub fn is_unix(&self) -> bool {
self.unix_path().is_some()
}
}
impl fmt::Display for Upstream {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.is_unix() {
return f.write_str(&self.authority());
}
write!(f, "{}://{}", self.scheme.as_str(), self.authority())
}
}