alireza0 建议在订阅路由统一设置禁止缓存头
alireza0 在 3x-ui PR #6862 中确认,raw、JSON 与 Clash 订阅响应携带实时流量、到期及路由信息,却缺少 Cache-Control,前置缓存可能返回旧数据。他建议把禁止缓存作为每个订阅路由组的中间件,替代分散在响应分支中的七处调用,以覆盖之后新增的分支。他还指出,现有自动识别 JSON 的测试未配置匹配正则,实际走的是 raw 分支,应按各个已注册路由组验证中间件。核对时 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.