Skip to content

Commit c0d146b

Browse files
committed
fix: fix public url port reading (#3172)
1 parent e5b2c86 commit c0d146b

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

packages/common/config/src/config/topology.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,19 @@ impl Datacenter {
9797
self.public_url.host_str() == Some(host)
9898
}
9999
}
100+
101+
pub fn public_url_host(&self) -> Result<&str> {
102+
self.public_url.host_str().context("no host")
103+
}
104+
105+
pub fn public_url_port(&self) -> Result<u16> {
106+
self.public_url
107+
.port()
108+
.or_else(|| match self.public_url.scheme() {
109+
"http" => Some(80),
110+
"https" => Some(443),
111+
_ => None,
112+
})
113+
.context("unsupported URL scheme")
114+
}
100115
}

packages/core/guard/server/src/routing/pegboard_gateway.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,12 @@ pub async fn route_request(
7676
targets: vec![RouteTarget {
7777
actor_id: Some(actor_id),
7878
host: peer_dc
79-
.public_url
80-
.host()
81-
.context("peer dc public_url has no host")?
79+
.public_url_host()
80+
.context("bad peer dc public url host")?
8281
.to_string(),
8382
port: peer_dc
84-
.public_url
85-
.port()
86-
.context("peer dc public_url has no port")?,
83+
.public_url_port()
84+
.context("bad peer dc public url port")?,
8785
path: path.to_owned(),
8886
}],
8987
timeout: RoutingTimeout {

0 commit comments

Comments
 (0)