From aaaca43c842766d91ba53cfe063fc4f727332ebe Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 19 Sep 2026 03:18:10 +0530 Subject: [PATCH] refactor(gateway): one wildcard-host predicate for the HTTP listeners Gate review: tcp_site.py grew its own `_WILDCARD_HOSTS` that already diverged from shared_ingress.py (dropped "*" and ""). One `is_wildcard_host` in shared_ingress, used by both the TIME_WAIT rebind guard and `listener_base_url`. --- gateway/platforms/shared_ingress.py | 7 ++++++- gateway/platforms/tcp_site.py | 10 ++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/gateway/platforms/shared_ingress.py b/gateway/platforms/shared_ingress.py index ae3db657e6..8018ce1290 100644 --- a/gateway/platforms/shared_ingress.py +++ b/gateway/platforms/shared_ingress.py @@ -24,6 +24,11 @@ logger = logging.getLogger(__name__) _WILDCARD_HOSTS = frozenset({"", "0.0.0.0", "::", "*"}) +def is_wildcard_host(host: Any) -> bool: + """True for the dual-stack default (None/"") and the per-family wildcards.""" + return host is None or str(host).strip() in _WILDCARD_HOSTS + + def shared_ingress_profile(adapter: Any) -> Optional[str]: """Profile name when *adapter* was constructed in shared-listener mode, else None.""" return getattr(adapter, "_shared_listener_profile", None) or None @@ -31,7 +36,7 @@ def shared_ingress_profile(adapter: Any) -> Optional[str]: def listener_base_url(host: Any, port: Any) -> str: """``http://host:port`` clients use to reach a listener bound on ``host`` (wildcards → loopback).""" - host = "127.0.0.1" if host is None or str(host).strip() in _WILDCARD_HOSTS else str(host) + host = "127.0.0.1" if is_wildcard_host(host) else str(host) if ":" in host and not host.startswith("["): host = f"[{host}]" return f"http://{host}:{port or 0}" diff --git a/gateway/platforms/tcp_site.py b/gateway/platforms/tcp_site.py index 6160075a5a..6be1aa63b2 100644 --- a/gateway/platforms/tcp_site.py +++ b/gateway/platforms/tcp_site.py @@ -10,16 +10,10 @@ from typing import Optional from aiohttp import web +from gateway.platforms.shared_ingress import is_wildcard_host + logger = logging.getLogger(__name__) -_WILDCARD_HOSTS = frozenset({"0.0.0.0", "::"}) - - -def is_wildcard_host(host: Optional[str]) -> bool: - """True for the dual-stack default (None/"") and the per-family wildcards.""" - return not host or host.strip() in _WILDCARD_HOSTS - - def has_live_listener(host: str, port: int) -> bool: """Blocking probe: True when something accepts connections on ``host:port``. Refused = nobody listens; any other failure (timeout, unroutable) is treated as live so the caller stays exclusive."""