mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Avoid double URL creation for hassio ingress (#105052)
This commit is contained in:
parent
b7bc49b863
commit
c2cc8014dc
@ -67,18 +67,20 @@ class HassIOIngress(HomeAssistantView):
|
|||||||
self._websession = websession
|
self._websession = websession
|
||||||
|
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def _create_url(self, token: str, path: str) -> str:
|
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)}"
|
url = f"http://{self._host}{base_path}{quote(path)}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not URL(url).path.startswith(base_path):
|
target_url = URL(url)
|
||||||
raise HTTPBadRequest()
|
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
raise HTTPBadRequest() from err
|
raise HTTPBadRequest() from err
|
||||||
|
|
||||||
return url
|
if not target_url.path.startswith(base_path):
|
||||||
|
raise HTTPBadRequest()
|
||||||
|
|
||||||
|
return target_url
|
||||||
|
|
||||||
async def _handle(
|
async def _handle(
|
||||||
self, request: web.Request, token: str, path: str
|
self, request: web.Request, token: str, path: str
|
||||||
@ -128,7 +130,7 @@ class HassIOIngress(HomeAssistantView):
|
|||||||
|
|
||||||
# Support GET query
|
# Support GET query
|
||||||
if request.query_string:
|
if request.query_string:
|
||||||
url = f"{url}?{request.query_string}"
|
url = url.with_query(request.query_string)
|
||||||
|
|
||||||
# Start proxy
|
# Start proxy
|
||||||
async with self._websession.ws_connect(
|
async with self._websession.ws_connect(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user