aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-05-03 12:25:01 +0200
committermetamuffin <metamuffin@disroot.org>2025-05-03 12:25:01 +0200
commita05c56befe3328448fcc497746986b9e13bfab18 (patch)
tree81d04556f179f25a905371936c7033d2ce776994
parentbe5e96ea29a875631b25ffb4ca6f410275b02d83 (diff)
downloadgnix-a05c56befe3328448fcc497746986b9e13bfab18.tar
gnix-a05c56befe3328448fcc497746986b9e13bfab18.tar.bz2
gnix-a05c56befe3328448fcc497746986b9e13bfab18.tar.zst
allow hostnames in proxy module
-rw-r--r--src/modules/proxy.rs13
1 files changed, 13 insertions, 0 deletions
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)