feat&fix: add proxy support in setup and remove hardcoded proxy from example

This commit is contained in:
adlsdztony
2025-07-01 13:47:16 +00:00
parent 64f47d1a32
commit 2f9ae1f3ad
3 changed files with 7 additions and 3 deletions

View File

@@ -47,11 +47,12 @@ class SetupController:
self.http_server: str = f"http://{vm_ip}:{server_port}"
self.http_server_setup_root: str = f"http://{vm_ip}:{server_port}/setup"
self.cache_dir: str = cache_dir
self.use_proxy: bool = False
def reset_cache_dir(self, cache_dir: str):
self.cache_dir = cache_dir
def setup(self, config: List[Dict[str, Any]])-> bool:
def setup(self, config: List[Dict[str, Any]], use_proxy: bool = False)-> bool:
"""
Args:
config (List[Dict[str, Any]]): list of dict like {str: Any}. each
@@ -63,6 +64,7 @@ class SetupController:
parameters
}
"""
self.use_proxy = use_proxy
# make sure connection can be established
logger.info(f"try to connect {self.http_server}")
retry = 0
@@ -237,6 +239,9 @@ class SetupController:
if not shell and isinstance(command, str) and len(command.split()) > 1:
logger.warning("Command should be a list of strings. Now it is a string. Will split it by space.")
command = command.split()
if command[0] == "google-chrome" and self.use_proxy:
command.append("--proxy-server=http://127.0.0.1:18888") # Use the proxy server set up by _proxy_setup
payload = json.dumps({"command": command, "shell": shell})
headers = {"Content-Type": "application/json"}