From 61a9055b31e06afa462f92344b3fe6b2d003b25e Mon Sep 17 00:00:00 2001 From: Martin Turoci Date: Thu, 12 Jan 2023 14:21:53 +0100 Subject: [PATCH] fix: Add forgotten loopback check. #982 --- py/h2o_wave/core.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/py/h2o_wave/core.py b/py/h2o_wave/core.py index 686dc609ab..6126117638 100644 --- a/py/h2o_wave/core.py +++ b/py/h2o_wave/core.py @@ -675,7 +675,7 @@ def upload(self, files: List[str]) -> List[str]: # If we know the path of waved and running app on the same machine, # we can simply copy the files instead of making an HTTP request. - if not skip_local_upload and waved_dir and data_dir: + if _is_loopback_address() and not skip_local_upload and waved_dir and data_dir: try: is_windows = 'Windows' in platform.system() cp_command = 'xcopy' if is_windows else 'cp' @@ -735,7 +735,7 @@ def upload_dir(self, directory: str) -> str: # If we know the path of waved and running app on the same machine, # we can simply copy the files instead of making an HTTP request. - if not skip_local_upload and waved_dir and data_dir: + if _is_loopback_address() and not skip_local_upload and waved_dir and data_dir: try: uuid = str(uuid4()) dst = os.path.join(waved_dir, data_dir, 'f', uuid) @@ -911,7 +911,7 @@ async def upload_dir(self, directory: str) -> str: # If we know the path of waved and running app on the same machine, # we can simply copy the files instead of making an HTTP request. - if not skip_local_upload and waved_dir and data_dir: + if _is_loopback_address() and not skip_local_upload and waved_dir and data_dir: try: uuid = str(uuid4()) dst = os.path.join(waved_dir, data_dir, 'f', uuid) @@ -959,7 +959,7 @@ async def upload(self, files: List[str]) -> List[str]: # If we know the path of waved and running app on the same machine, # we can simply copy the files instead of making an HTTP request. - if not skip_local_upload and waved_dir and data_dir: + if _is_loopback_address() and not skip_local_upload and waved_dir and data_dir: try: tasks = [] for f in files: @@ -1137,9 +1137,9 @@ def pack(data: Any) -> str: return 'data:' + marshal(_dump(data)) -def _is_loopback_address(address: str) -> bool: +def _is_loopback_address() -> bool: try: - hostname = urlparse(address).hostname + hostname = urlparse(_config.hub_address).hostname return ipaddress.ip_address(hostname).is_loopback except ValueError: return False