Commit Graph

41 Commits

Author SHA1 Message Date
Aqr-K
0fb11880a4 perf(http): AsyncRequestUtils 默认启用 HTTP/2
为 AsyncRequestUtils 增加 http2: bool = True 参数(默认开启),
内部贯穿到 _get_shared_async_transport 与 path C 兜底 AsyncClient。
http2 加入共享 AsyncHTTPTransport 桶 key,让不同 h2 设置自动隔离。

启用基于 TLS ALPN:服务端宣告支持 h2 时切到 HTTP/2 多路复用;
不支持(含明文 HTTP、老 nginx/Apache)透明回落 HTTP/1.1。如个别
站点 h2 实现异常,调用方传 http2=False 单独关闭。

依赖:httpx extras 由 [socks] 扩展为 [socks,http2],引入纯 Python
包 h2 / hpack / hyperframe(无原生扩展)。

真实 TMDB 压测(30 部美剧 × 每部 50 集 = 3060 请求/版本):
HTTP/1.1 52.0s → HTTP/2 27.6s,节省 24.4s(1.88×)。
单请求 p95 由 96.1ms 降至 20.1ms,长尾大幅收敛。

公共 API 表面零变动;插件可按需 http2=False 单点关闭。
2026-05-11 17:15:23 +08:00
jxxghp
1b2433f7c2 feat: implement runtime dependency checks and recovery for plugin installations 2026-05-11 08:54:34 +08:00
Aqr-K
c745616495 perf(http): 异步 HTTP 引入共享 AsyncHTTPTransport,复用 TCP/TLS 握手
AsyncRequestUtils 使用按事件循环弱引用持有的共享
AsyncHTTPTransport 作为底层连接池与 TLS 会话;每次请求创建轻量
AsyncClient 承载本次 cookie jar、timeout、follow_redirects,
用完即销毁。共享 transport 由 _NonClosingTransportProxy 包装后
注入 AsyncClient,吞掉 AsyncClient 退出时向底层 transport
传播的 __aexit__/aclose,使底层连接池跨调用持久,从而真正复用
TCP/TLS 握手。

设计要点:
- 共享 transport 桶按 (proxy, verify, max_keepalive_connections,
  max_connections, keepalive_expiry) 区分;每事件循环 32 桶 LRU
  上限,超出后异步关闭最久未用桶;关闭 task 由模块级强引用集合
  持有以兼容 Python 3.11+ 的任务 GC 行为。
- 通过 FastAPI lifespan shutdown 调用 aclose_shared_async_transports
  集中释放底层 transport,避免 ResourceWarning。
- AsyncRequestUtils.request 走三条 path:用户自管 client / 共享
  transport + per-call AsyncClient / 兜底临时 client。三条路径
  cookie 语义一致;后两条因 per-call AsyncClient 生命周期局限于
  单次调用,天然不积累 Set-Cookie,避免跨调用 jar 演化串扰。
- _make_request 对幂等方法(GET/HEAD/OPTIONS)在
  RemoteProtocolError / ReadError / WriteError 时单次重试,
  容忍 keep-alive stale 连接命中;非幂等方法不重试,但记录
  debug 日志。
- get_stream 使用 httpx.AsyncClient.stream() 标准流式 API,与
  request 共用三条 path 的 client 选择逻辑;幂等单次重试;
  yield 体异常透传给 stream 的 __aexit__。

公共 API 表面零变动。插件可通过 max_keepalive_connections /
max_connections / keepalive_expiry 三个 limits 参数为自己定制
连接池容量与握手有效期。

TMDB 真实压测(10 部美剧 × 每部 50 集,1020 请求):
61.96s → 18.15s(3.41×),单请求 p95 149.6ms → 38.1ms。
2026-05-11 08:46:40 +08:00
jxxghp
4c32ad902b Harden system nettest SSRF handling 2026-04-18 17:43:38 +08:00
InfinityPacer
815d83bfb3 fix(http): close helper responses consistently 2026-04-10 18:21:30 +08:00
InfinityPacer
217fcfd1b2 fix(http): close non-success responses safely 2026-04-10 18:21:30 +08:00
hyuan280
f89d6342d1 fix: 修复Cookie解码二进制数据导致请求发送时UnicodeEncodeError 2026-01-21 16:36:28 +08:00
xjy
ce83bc24bd fix: 修复站点Cookie处理的两个关键问题
本次提交修复了PT站点搜索功能失败的两个根本原因:

1. **Cookie URL解码问题**
   - 问题:数据库中存储的Cookie值包含URL编码(如%3D、%2B、%2F),
     但cookie_parse()函数未进行解码
   - 影响:所有使用URL编码Cookie的站点可能无法正常登录
   - 修复:在app/utils/http.py的cookie_parse()中添加unquote()解码

2. **httpx Cookie jar覆盖问题**(关键)
 - 问题:httpx.AsyncClient的Cookie jar机制会自动保存服务器返回的
 Set-Cookie,并在后续请求中覆盖我们传入的Cookie
 - 表现:传入正确的c_secure_uid/c_secure_pass,实际发送的却是
 PHPSESSID等错误Cookie
 - 修复:在创建AsyncClient时传入Cookie,而不是在request()时传入

修改文件:
- app/utils/http.py: cookie_parse()添加URL解码 + AsyncClient传入cookies
- app/modules/indexer/spider/__init__.py: 清理调试代码

测试验证:
-  pterclub 搜索功能恢复正常
-  春天站点搜索功能正常(验证通用性)
2026-01-13 09:29:05 +08:00
jxxghp
90f74d8d2b feat:支持FlareSolverr 2025-08-11 21:14:46 +08:00
jxxghp
c8749b3c9c add aiopath 2025-07-30 19:49:59 +08:00
jxxghp
5f6310f5d6 fix httpx proxy 2025-07-30 17:34:09 +08:00
jxxghp
42d955b175 重构订阅和用户相关API,支持异步操作 2025-07-30 15:23:25 +08:00
jxxghp
f077a9684b 添加异步请求工具类;优化fetch_image和proxy_img函数为异步实现提升性能 2025-07-30 08:30:24 +08:00
jxxghp
7a1cbf70e3 feat:特定默认UA 2025-07-14 12:35:08 +08:00
景大侠
6c02766000 AutoCloseResponse支持上下文管理协议,避免部分插件报错 2025-07-03 18:38:48 +08:00
景大侠
8146b680c6 fix: 修复AutoCloseResponse类在反序列化时无限递归 2025-07-01 01:29:01 +08:00
Attente
0f0c3e660b style: 清理空白字符
移除代码中的 trailing whitespace 和空行缩进, 提升代码整洁度
2025-06-29 22:49:58 +08:00
jxxghp
23c9862eb3 fix site parser 2025-06-27 12:26:17 +08:00
jxxghp
d8a53da8ee auto close RequestUtils 2025-06-27 08:30:57 +08:00
jxxghp
9555ac6305 fix RequestUtils 2025-06-27 08:09:38 +08:00
jxxghp
27dd681d9f fix RequestUtils 2025-06-26 17:36:22 +08:00
jxxghp
5d188e3877 fix module close 2025-06-03 17:11:44 +08:00
jxxghp
aa93c560e5 feat:分享订阅删除功能 2025-01-15 13:31:16 +08:00
InfinityPacer
2e7e74c803 feat(encoding): update configuration to performance mode 2024-11-27 13:52:17 +08:00
InfinityPacer
83fc474dbe feat(encoding): enhance encoding detection with confidence threshold 2024-11-27 12:33:57 +08:00
InfinityPacer
89819f8730 feat(cache): add HTTP cache support for image proxy 2024-10-14 17:00:27 +08:00
InfinityPacer
efb624259a fix(Utils): remove unnecessary methods 2024-10-13 22:40:58 +08:00
InfinityPacer
93b899b7e9 refactor(UrlUtils): Migrate URL-related methods from RequestUtils 2024-08-21 22:12:56 +08:00
jxxghp
1f87bc643a sync main 2024-08-19 13:06:39 +08:00
InfinityPacer
6392ee627f fix 请求失败时记录debug日志 2024-06-19 16:36:31 +08:00
InfinityPacer
cb0bb8a38e refactor request host 2024-06-19 15:51:57 +08:00
InfinityPacer
de2323d67a refactor RequestUtils 2024-06-19 13:45:02 +08:00
jxxghp
ffac57ad4d 支持 YemaPT 2024-05-20 16:55:36 +08:00
jxxghp
2ee477c35e fix requests session stream 2023-10-05 17:32:23 -07:00
jxxghp
1a49c7c59e try fix 2023-10-05 07:44:21 +08:00
jxxghp
e3707f39bb fix wallpaper 2023-09-22 11:33:25 +08:00
jxxghp
0e36d003c0 fix db session 2023-09-09 19:26:56 +08:00
jxxghp
5dc11b07e3 fix #342 2023-09-01 17:30:21 +08:00
jxxghp
14d3ff6477 fix webhooks 2023-06-11 20:44:51 +08:00
jxxghp
1e82ecc16c fix 索引乱码问题 2023-06-11 18:58:29 +08:00
jxxghp
4d06f86e62 init 2023-06-06 07:15:17 +08:00