alireza0:3x-ui 订阅响应应由路由组统一禁止缓存
alireza0 在 3x-ui PR #6862 评论中指出 raw、JSON 和 Clash 订阅响应含实时状态却缺少 Cache-Control,建议在 initRouter 的各订阅路由组统一挂 no-store 中间件,覆盖现有及未来分支,并修正自动识别 JSON 测试重复的问题。该评论是对订阅缓存行为和测试覆盖的具体技术结论,PR 随后已合并。
作者原文@alireza0Thanks, the problem is real: the raw, JSON and Clash bodies carry live traffic, expiry and routing headers but go out with no
Cache-Control, so any cache in front of the sub server can serve stale data.Please make it a rule of the routes rather than of the branches. Every route
initRouterregisters is a per-subscriber:subidendpoint, and none of them should ever be cached. Today the rule lives in 7 scattered calls: the 4 existing ones (info, the HTML page twice, hwid-status) plus the 3 this PR adds. The next body branch someone adds will miss it again. A small middleware that callssetNoCacheHeadersattached to each group ininitRouter(subPath,subJsonPath,subClashPath, and the mihomo and legacy Clash aliases) covers every current and future branch, and lets all 7 inline calls go.Test:
- The "auto-detected JSON" case never reaches the JSON branch.
newSubscriptionTestRoutersets nojsonUserAgentRegexand the default is empty, soHapp/2.0is served by the raw branch and the case duplicates "raw base64 body". With the middleware, one case per registered route group is enough:/sub/,/json/,/clash/, the mihomo alias and the legacy Clash alias. Each one should fail if its group lacks the middleware.- The comment above the test is three lines; our limit is two per block.