Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: leave a bracketed IPv6 host unchanged in dial_host (#12733)

Younes Berianeadf23cc0f256
diff --git a/studio/backend/tests/test_bind_host_policy.py b/studio/backend/tests/test_bind_host_policy.py
index 22b7d08ba24..f9126977e29 100644
--- a/studio/backend/tests/test_bind_host_policy.py
+++ b/studio/backend/tests/test_bind_host_policy.py
@@ -9,6 +9,7 @@ import pytest
from utils import host_policy
from utils.host_policy import (
+ dial_host,
is_wildcard_host,
normalize_wildcard_bind_host,
resolved_bind_address_count,
@@ -249,12 +250,27 @@ def test_run_server_rejects_an_ephemeral_multi_address_bind(monkeypatch):
("fe80::1234%eth0", "[fe80::1234%25eth0]"),
("fe80::1234%12", "[fe80::1234%2512]"),
("[::1]", "[::1]"),
+ ("[fe80::1234%eth0]", "[fe80::1234%25eth0]"),
],
)
def test_published_url_host_builds_a_url_authority(host, expected):
assert published_url_host(host) == expected
+ "host, expected",
+ [
+ ("127.0.0.1", "127.0.0.1"),
+ ("::1", "[::1]"),
+ ("[::1]", "[::1]"),
+ ("fe80::1%en0", "[fe80::1%en0]"),
+ ("[fe80::1%en0]", "[fe80::1%en0]"),
+ ],
+)
+def test_dial_host_builds_a_dialable_url_authority(host, expected):
+ assert dial_host(host) == expected
+
+
def test_run_server_publishes_urls_through_the_shared_formatter():
import run
assert run._url_host is published_url_host
diff --git a/studio/backend/utils/host_policy.py b/studio/backend/utils/host_policy.py
index 24664fbc553..371845acf50 100644
--- a/studio/backend/utils/host_policy.py
+++ b/studio/backend/utils/host_policy.py
@@ -164,17 +164,20 @@ def wildcard_loopback_host(host: str) -> "str | None":
return "::1" if 6 in versions else None
+def _bracket_ipv6(host: str) -> str:
+ if ":" not in host or (host.startswith("[") and host.endswith("]")):
+ return host
+ return f"[{host}]"
+
+
def published_url_host(host: str) -> str:
"""Authority host for a URL Studio hands out - a banner line, `server_url`, a tunnel origin."""
- escaped = host.replace("%", "%25")
- if ":" not in escaped or (escaped.startswith("[") and escaped.endswith("]")):
- return escaped
- return f"[{escaped}]"
+ return _bracket_ipv6(host.replace("%", "%25"))
def dial_host(host: str) -> str:
"""Authority host for a URL this process dials itself. The IPv6 zone id stays literal: httpx hands the RFC 6874 escaping `published_url_host` applies to the resolver unchanged."""
- return f"[{host}]" if ":" in host else host
+ return _bracket_ipv6(host)
# Self-call address resolution. A `--host` other than a wildcard binds one interface only, so loopback is not served and a hardcoded `127.0.0.1` self-call cannot connect.