Fixed port assumption

This commit is contained in:
patben8 committed 2026-10-04 17:13:24 +02:00
1 parent e5fb0f0dbb
commit ba7b662b93
3 files changed
+31 -6

No files matched your search

+10 -3
View File
@@ -36,10 +36,15 @@ class Remote:
username: str = ""
def addresses(self) -> list[tuple[str, str]]:
"""`(label, base url)`, primary first — the order every connect tries."""
"""`(label, base url)`, primary first — the order every connect tries.
Each address keeps its OWN port. The fallback once borrowed the
primary's, so a reverse-proxied fallback (`konduktor.example.net`,
served on 443) was tried at `:8765` because the LAN address named it.
"""
out = [("primary", _base(self.host, self.port))]
if self.fallback_host:
out.append(("fallback", _base(self.fallback_host, self.fallback_port or self.port)))
out.append(("fallback", _base(self.fallback_host, self.fallback_port)))
return out
def public(self) -> dict:
@@ -47,9 +52,11 @@ class Remote:
def _base(host: str, port: int | None) -> str:
"""An address as typed → a base URL. A full URL (`https://…`, the way to
reach a server behind the user's own reverse proxy) is taken exactly as
given, port and all; anything else is plain HTTP on its port, else 8765."""
host = host.strip()
if host.startswith("http://") or host.startswith("https://"):
# A full URL (behind the user's own reverse proxy): taken as given.
return host.rstrip("/")
bare, inline = split_host(host)
if inline is not None:
+18
View File
@@ -121,6 +121,24 @@ back = rp.unpack_analysis(rp.pack_analysis(PreparedAnalysis(measured=measured, k
check("…and the detected key", back.key == key, back.key)
check("no analysis is None", rp.pack_analysis(None) is None and rp.unpack_analysis(None) is None)
print("== remote addresses ==")
from konduktor.adapters.remote.config import Remote
r = Remote(id="r", name="NAS", host="192.168.1.20", port=8765, fallback_host="konduktor.example.net")
check("each address is built from its own parts",
r.addresses() == [("primary", "http://192.168.1.20:8765"), ("fallback", "http://konduktor.example.net:8765")],
r.addresses())
r = Remote(id="r", name="NAS", host="192.168.1.20", port=9000, fallback_host="konduktor.example.net")
check("…so a bare fallback gets the default port, not the primary's 9000",
r.addresses()[1] == ("fallback", "http://konduktor.example.net:8765"), r.addresses())
r = Remote(id="r", name="NAS", host="192.168.1.20", port=9000, fallback_host="https://konduktor.example.net/")
check("a full URL is used exactly as typed (a reverse proxy's port)",
r.addresses()[1] == ("fallback", "https://konduktor.example.net"), r.addresses())
r = Remote(id="r", name="NAS", host="http://nas.lan:8080")
check("…a URL with its own port keeps it", r.addresses() == [("primary", "http://nas.lan:8080")])
check("host:port typed inline is split", Remote(id="r", name="N", host="nas.local:9001").addresses()[0][1]
== "http://nas.local:9001")
print("== versions ==")
check("same version talks", rp.compatible((1, 0), (1, 0)) is None)
check("a newer server minor talks", rp.compatible((1, 0), (1, 3)) is None)