Skip to content

The only downloader you need. 下载器的集大成者。

refactor(proxy): 重构系统代理获取逻辑

XiaoYouChR7daeb80c5f3b
diff --git a/app/supports/utils.py b/app/supports/utils.py
index e4726296..1bef9539 100644
--- a/app/supports/utils.py
+++ b/app/supports/utils.py
@@ -117,11 +117,13 @@ def _getWindowsSystemProxies() -> dict[str, str]:
return proxiesWithCredentials
-def _getLinuxSystemProxies() -> dict[str, str]:
+def _getEnvSystemProxies() -> dict[str, str]:
+ allProxy = str(os.environ.get("all_proxy") or os.environ.get("ALL_PROXY") or "").strip()
proxies = {
protocol: str(
os.environ.get(f"{protocol}_proxy")
or os.environ.get(f"{protocol.upper()}_PROXY")
+ or allProxy
or ""
).strip()
for protocol in _PROXY_PROTOCOLS
@@ -135,10 +137,17 @@ def _getLinuxSystemProxies() -> dict[str, str]:
return {protocol: proxyUrl for protocol, proxyUrl in proxies.items() if proxyUrl}
+def _getLinuxSystemProxies() -> dict[str, str]:
+ return _getEnvSystemProxies()
+
+
def _getDarwinSystemProxies() -> dict[str, str]:
- import SystemConfiguration
+ try:
+ import SystemConfiguration
+ proxySettings = SystemConfiguration.SCDynamicStoreCopyProxies(None) # type: ignore
+ except Exception:
+ return _getEnvSystemProxies()
- proxySettings = SystemConfiguration.SCDynamicStoreCopyProxies(None) # type: ignore
if proxySettings.get("SOCKSEnable", 0):
proxyUrl = f"socks5://{proxySettings.get('SOCKSProxy')}:{proxySettings.get('SOCKSPort')}"
return {protocol: proxyUrl for protocol in _PROXY_PROTOCOLS}
@@ -147,7 +156,7 @@ def _getDarwinSystemProxies() -> dict[str, str]:
proxyUrl = f"http://{proxySettings.get('HTTPProxy')}:{proxySettings.get('HTTPPort')}"
return {protocol: proxyUrl for protocol in _PROXY_PROTOCOLS}
- return {}
+ return _getEnvSystemProxies()
def getSystemProxies() -> dict[str, str] | None: