mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 10:10:43 +00:00
被控端 - 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%) - 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败) - 每分钟回头找局域网,自动切回快 400 倍的路径 - 画面心跳帧:静止时省流量,客户端仍知道流是活的 - 锁屏时给出可操作的提示 手表端 - 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException - 连接错误翻译成人话(证书/时间/解析/超时分别提示) - 经中转连上后用服务器报的地址刷新已配对记录 - 新增局域网连接页面、服务器延迟检测 服务器端 - 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502) - 网络调优脚本 net-tune.sh(开机自动应用) - 管理页:批量删除、网络体检、下载区 - 隧道改 HTTP/2 + 双连接 文档 - 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""修测试里的 get() 帮助函数:裸 urlopen 不带 UA 会被 Cloudflare 拦。
|
||
|
||
test_relay_e2e.py 里的 get() 是这么写的:
|
||
with urllib.request.urlopen(URL + path, timeout=timeout) as resp:
|
||
|
||
urlopen 直接接 URL 字符串时不能带 headers,
|
||
必须包一个 Request 才行。三个测试脚本里的 post() 已经改对了,
|
||
get() 还没改。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
TESTS = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\_tests")
|
||
FILES = ["test_relay_e2e.py", "test_relay_local.py", "test_relay_admin_login.py"]
|
||
|
||
# 匹配:with urllib.request.urlopen(<非 req 变量>, ...) as <var>:
|
||
PATTERN = re.compile(
|
||
r"urllib\.request\.urlopen\(\s*(URL \+ path|RELAY_URL \+ path)\s*,"
|
||
r"\s*(timeout=[^)]*)\)")
|
||
|
||
|
||
def main() -> int:
|
||
ok = True
|
||
for name in FILES:
|
||
path = TESTS / name
|
||
if not path.is_file():
|
||
continue
|
||
text = path.read_text(encoding="utf-8")
|
||
if "_UA" not in text:
|
||
print(f" {name}: 没有 _UA,跳过")
|
||
continue
|
||
|
||
hits = PATTERN.findall(text)
|
||
if not hits:
|
||
print(f" {name}: get() 已经改过")
|
||
continue
|
||
|
||
# 把每处换成先建 Request 再 urlopen
|
||
text = PATTERN.sub(
|
||
lambda m: (f'_req = urllib.request.Request({m.group(1)}, '
|
||
f'headers=_UA)\n'
|
||
f' with urllib.request.urlopen(_req, {m.group(2)}) '
|
||
f'as resp:'),
|
||
text)
|
||
|
||
# 上面的替换会把 "with " 留在前面,形成 "with _req = ..." 这种错误
|
||
text = text.replace("with _req = urllib.request.Request(",
|
||
"_req = urllib.request.Request(")
|
||
|
||
path.write_text(text, encoding="utf-8", newline="\n")
|
||
|
||
import ast
|
||
try:
|
||
ast.parse(text)
|
||
print(f" {name}: 改了 {len(hits)} 处,语法 OK")
|
||
except SyntaxError as exc:
|
||
print(f" {name}: 语法错误 {exc}")
|
||
ok = False
|
||
return 0 if ok else 1
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|