Unified proxy configuration determination function. Priority: Command-line arguments > Environment variables > System settings.
(
internal_camoufox_proxy_arg: Optional[str] = None,
)
| 28 | |
| 29 | |
| 30 | def determine_proxy_configuration( |
| 31 | internal_camoufox_proxy_arg: Optional[str] = None, |
| 32 | ) -> Dict[str, Optional[str]]: |
| 33 | """ |
| 34 | Unified proxy configuration determination function. |
| 35 | Priority: Command-line arguments > Environment variables > System settings. |
| 36 | """ |
| 37 | result = {"camoufox_proxy": None, "stream_proxy": None, "source": "No Proxy"} |
| 38 | |
| 39 | if internal_camoufox_proxy_arg is not None: |
| 40 | if internal_camoufox_proxy_arg.strip(): |
| 41 | result["camoufox_proxy"] = internal_camoufox_proxy_arg.strip() |
| 42 | result["stream_proxy"] = internal_camoufox_proxy_arg.strip() |
| 43 | result["source"] = ( |
| 44 | f"CLI argument --internal-camoufox-proxy: {internal_camoufox_proxy_arg.strip()}" |
| 45 | ) |
| 46 | else: |
| 47 | result["source"] = ( |
| 48 | "CLI argument --internal-camoufox-proxy='' (Explicitly disabled)" |
| 49 | ) |
| 50 | return result |
| 51 | |
| 52 | unified_proxy = os.environ.get("UNIFIED_PROXY_CONFIG") |
| 53 | if unified_proxy: |
| 54 | result["camoufox_proxy"] = unified_proxy |
| 55 | result["stream_proxy"] = unified_proxy |
| 56 | result["source"] = f"Environment variable UNIFIED_PROXY_CONFIG: {unified_proxy}" |
| 57 | return result |
| 58 | |
| 59 | http_proxy = os.environ.get("HTTP_PROXY") |
| 60 | if http_proxy: |
| 61 | result["camoufox_proxy"] = http_proxy |
| 62 | result["stream_proxy"] = http_proxy |
| 63 | result["source"] = f"Environment variable HTTP_PROXY: {http_proxy}" |
| 64 | return result |
| 65 | |
| 66 | https_proxy = os.environ.get("HTTPS_PROXY") |
| 67 | if https_proxy: |
| 68 | result["camoufox_proxy"] = https_proxy |
| 69 | result["stream_proxy"] = https_proxy |
| 70 | result["source"] = f"Environment variable HTTPS_PROXY: {https_proxy}" |
| 71 | return result |
| 72 | |
| 73 | if sys.platform.startswith("linux"): |
| 74 | gsettings_proxy = get_proxy_from_gsettings() |
| 75 | if gsettings_proxy: |
| 76 | result["camoufox_proxy"] = gsettings_proxy |
| 77 | result["stream_proxy"] = gsettings_proxy |
| 78 | result["source"] = f"gsettings System Proxy: {gsettings_proxy}" |
| 79 | return result |
| 80 | |
| 81 | return result |
| 82 | |
| 83 | |
| 84 | def parse_args() -> argparse.Namespace: |