alireza0 指出 s-ui Clash 导出会丢失 XHTTP 与外部链接 ALPN
在 s-ui #1295 的合并前评审中,alireza0 确认 type=xhttp 的 VLESS 外部链接会在 Clash 导出中丢失传输设置、退化为普通 TCP。他称已核对 Mihomo 选项并通过相关检查,同时要求修改 API 形式、拆分 XHTTP 映射代码。他还指出 ALPN 类型不匹配影响所有外部链接的 Clash 导出,建议在转换器中同时接受两种切片类型;TLS 下载的空 reality-opts 不应继承上行 REALITY。
作者原文@alireza0Thanks for this, it's a real fix. Today a
type=xhttpVLESS link gets no transport at all and ends up as plain TCP in the Clash export.I checked it against
main: no conflicts, andgo vetand thesub/utiltests pass with-race. I also compared every key inxhttp-opts,reuse-settingsanddownload-settingswith Mihomo'sXHTTPOptions/XHTTPDownloadSettings, and they all match. Leavingreality-optsempty for a TLS download is right too: Mihomo'sRealityOptions.Parse()returns no config when the public key is empty, so the download side doesn't pick up REALITY from the uplink.A few changes before merging:
- Avoid the variadic
forClash ...bool. Adding an optional bool to two exported functions (GetExternalOutbounds,GetExternalSub) makes call sites hard to read and easy to get wrong. Please use an explicit parameter, or a separate Clash-specific function.
- Fix ALPN in the converter, not only in the XHTTP path.
linkToJsonbuildstls.alpnas[]string, butConvertToClashMetaonly accepts[]interface{}(sub/clashService.go, thetls["alpn"]check). Because of that, ALPN is dropped for every external link in the Clash export, not only XHTTP ones. It would be cleaner to accept both types there and remove the[]string→[]interface{}conversion fromGetOutboundForClash.
- Move the XHTTP mapping into its own file. The ~250 lines of
xhttp*helpers would read better in something likesub/clash_xhttp.gothan insideclashService.go.
- Minor: in
GetOutboundForClash, thejson.Validcall beforeDecodeisn't needed, becauseDecodealready returns an error for invalid JSON.The
GetExternalSubchange that trims lines and skips empty ones is a nice side fix for CRLF subscriptions. Please keep it.