From 259a1ae41f2619c3ba9941d28f757294809ac045 Mon Sep 17 00:00:00 2001 From: RoyirinRosmontis Date: Thu, 10 Sep 2026 20:55:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=20-=20=E8=8A=82?= =?UTF-8?q?=E7=82=B9=20HTTP=20=E4=BB=A3=E7=90=86=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E4=B8=8D=E5=88=B0=E7=9C=9F=E5=AE=9E=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=AF=BC=E8=87=B4=E8=AE=A4=E8=AF=81=E6=81=92=E4=B8=BA?= =?UTF-8?q?=20401=EF=BC=9A=E6=96=B0=E5=A2=9E=20=5Fhttp=5Fmethod()=EF=BC=8C?= =?UTF-8?q?=5Fendpoint=5Fport()=20=E4=B8=8E=20=5Fproxy=5Fauth=5Fbasic()=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BC=98=E5=85=88=E8=AF=BB=E5=8F=96=E6=96=B0?= =?UTF-8?q?=E7=89=88=20nodes.json=20=E7=9A=84=20methods.http.port/username?= =?UTF-8?q?/password=EF=BC=8C=E7=BC=BA=E5=A4=B1=E6=97=B6=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E9=A1=B6=E5=B1=82=E9=94=AE=EF=BC=88=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=97=A7=E6=89=81=E5=B9=B3=E7=BB=93=E6=9E=84=EF=BC=89?= =?UTF-8?q?=20-=20=E5=AE=9E=E6=B5=8B=E5=8E=9F=E9=80=BB=E8=BE=91=E4=B8=8B?= =?UTF-8?q?=E6=89=80=E6=9C=89=E8=8A=82=E7=82=B9=E5=9D=87=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=20401=20Authorization=20Required=EF=BC=88=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E4=B8=B2=E4=B8=BA=E7=A9=BA=EF=BC=8CUS=20=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E4=B9=9F=E4=BB=8E=201205=20=E8=90=BD?= =?UTF-8?q?=E5=88=B0=E9=BB=98=E8=AE=A4=20443=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lite/proxy_lite.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lite/proxy_lite.py b/lite/proxy_lite.py index ce07798..faff0ae 100644 --- a/lite/proxy_lite.py +++ b/lite/proxy_lite.py @@ -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