修复:

- 节点 HTTP 代理参数读取不到真实字段导致认证恒为 401:新增 _http_method(),_endpoint_port() 与 _proxy_auth_basic() 改为优先读取新版 nodes.json 的 methods.http.port/username/password,缺失时回退节点顶层键(兼容旧扁平结构)
- 实测原逻辑下所有节点均返回 401 Authorization Required(认证串为空,US 节点端口也从 1205 落到默认 443)
This commit is contained in:
RoyirinRosmontis
2026-09-10 20:56:12 +08:00
parent bcb113e8c9
commit 259a1ae41f
+27 -6
View File
@@ -162,18 +162,39 @@ def _node_val(key, default=""):
def _endpoint_domain():
return _node_val("domain", "???")
def _http_method():
"""节点 HTTP 代理方法参数(新版 nodes.json 的 methods.http)。
返回 (node, get):get(key, default) 优先取 methods.http 下的键,
缺失时回退节点顶层——兼容旧扁平结构(port/username/password 直接挂在节点上)。
"""
node = _current_node() or {}
m = (node.get("methods") or {}).get("http") or {}
def get(key, default=""):
v = m.get(key)
if v in (None, ""):
v = node.get(key)
return default if v in (None, "") else v
return node, get
def _endpoint_port():
return int(_node_val("port", 443))
"""HTTP 代理端口:methods.http.port(新格式)或节点顶层 port(旧格式)。"""
_, get = _http_method()
try:
return int(get("port", 443))
except (TypeError, ValueError):
return 443
def _endpoint_country():
return _node_val("country", "")
def _proxy_auth_basic():
"""与 nginx 正向代理使用同一套 Basic 认证凭证(取自 nodes.json)。"""
node = _current_node()
if not node:
return ""
return base64.b64encode(f"{node.get('username', '')}:{node.get('password', '')}".encode()).decode()
"""正向代理 Basic 认证凭证:methods.http.{username,password}(新格式)
或节点顶层同名字段(旧格式);用于转发器向上游代理注入 Authorization。"""
_, get = _http_method()
return base64.b64encode(f"{get('username')}:{get('password')}".encode()).decode()
_tls_forwarder = None
_pac_server = None