Avoid netloc ipaddress re-encoding to construct ingress urls (#116431)

This commit is contained in:
J. Nick Koston 2024-04-30 11:44:25 -05:00 committed by GitHub
parent ff104f54b5
commit 6be2b334d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,15 +67,15 @@ class HassIOIngress(HomeAssistantView):
"""Initialize a Hass.io ingress view.""" """Initialize a Hass.io ingress view."""
self._host = host self._host = host
self._websession = websession self._websession = websession
self._url = URL(f"http://{host}")
@lru_cache @lru_cache
def _create_url(self, token: str, path: str) -> URL: def _create_url(self, token: str, path: str) -> URL:
"""Create URL to service.""" """Create URL to service."""
base_path = f"/ingress/{token}/" base_path = f"/ingress/{token}/"
url = f"http://{self._host}{base_path}{quote(path)}"
try: try:
target_url = URL(url) target_url = self._url.join(URL(f"{base_path}{quote(path)}"))
except ValueError as err: except ValueError as err:
raise HTTPBadRequest from err raise HTTPBadRequest from err