Avoid double URL creation for hassio ingress (#105052)

This commit is contained in:
J. Nick Koston 2023-12-04 22:29:43 -10:00 committed by GitHub
parent b7bc49b863
commit c2cc8014dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,18 +67,20 @@ class HassIOIngress(HomeAssistantView):
self._websession = websession
@lru_cache
def _create_url(self, token: str, path: str) -> str:
def _create_url(self, token: str, path: str) -> URL:
"""Create URL to service."""
base_path = f"/ingress/{token}/"
url = f"http://{self._host}{base_path}{quote(path)}"
try:
if not URL(url).path.startswith(base_path):
raise HTTPBadRequest()
target_url = URL(url)
except ValueError as err:
raise HTTPBadRequest() from err
return url
if not target_url.path.startswith(base_path):
raise HTTPBadRequest()
return target_url
async def _handle(
self, request: web.Request, token: str, path: str
@ -128,7 +130,7 @@ class HassIOIngress(HomeAssistantView):
# Support GET query
if request.query_string:
url = f"{url}?{request.query_string}"
url = url.with_query(request.query_string)
# Start proxy
async with self._websession.ws_connect(