From a05c56befe3328448fcc497746986b9e13bfab18 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 3 May 2025 12:25:01 +0200 Subject: allow hostnames in proxy module --- src/modules/proxy.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/modules/proxy.rs b/src/modules/proxy.rs index 2d6b254..aecd775 100644 --- a/src/modules/proxy.rs +++ b/src/modules/proxy.rs @@ -40,6 +40,7 @@ struct Proxy { #[derive(Debug)] enum SocketAddrOrPath { + Host(String), Ip(SocketAddr), Unix(PathBuf), } @@ -65,6 +66,8 @@ impl<'de> Deserialize<'de> for SocketAddrOrPath { let s = String::deserialize(deserializer)?; if s.starts_with("/") { Ok(Self::Unix(PathBuf::from_str(&s).map_err(|e| match e {})?)) + } else if let Some(host) = s.strip_prefix("@") { + Ok(Self::Host(host.to_string())) } else if let Some(port) = s.strip_prefix(":") { Ok(Self::Ip(SocketAddr::V4(SocketAddrV4::new( Ipv4Addr::LOCALHOST, @@ -82,6 +85,7 @@ impl Display for SocketAddrOrPath { match self { SocketAddrOrPath::Ip(addr) => write!(f, "{addr}"), SocketAddrOrPath::Unix(path) => write!(f, "unix:{}", path.to_string_lossy()), + SocketAddrOrPath::Host(host) => write!(f, "host:{host}"), } } } @@ -155,6 +159,15 @@ impl Node for Proxy { ) .await? } + SocketAddrOrPath::Host(host) => { + send_request( + TcpStream::connect(host) + .await + .map_err(|_| ServiceError::CantConnect)?, + request, + ) + .await? + } SocketAddrOrPath::Unix(path) => { send_request( UnixStream::connect(path) -- cgit v1.2.3-70-g09d2