diff --git a/backend/package.json b/backend/package.json index be105490..17866cf1 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.21.60", + "version": "2.21.61", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index ffef31be..7b1655ee 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -829,13 +829,33 @@ function URI_VLESS() { // mKCP 的伪装头部类型。当前可选值有 none / srtp / utp / wechat-video / dtls / wireguard。省略时默认值为 none,即不使用伪装头部,但不可以为空字符串。 proxy.headerType = params.headerType || 'none'; } - - if (params.mode) { - proxy._mode = params.mode; - } if (params.extra) { proxy._extra = params.extra; } + // 太麻烦了 暂时 extra 原封不动 + // 单独解析一下 + if (params.mode) { + if (['xhttp'].includes(proxy.network)) { + let extra = {}; + try { + extra = proxy._extra ? JSON.parse(proxy._extra) : {}; + } catch (e) { + $.error( + `Failed to parse extra field as JSON: ${proxy._extra}`, + ); + } + proxy[`${proxy.network}-opts`] = { + 'no-grpc-header': extra['noGRPCHeader'], + 'x-padding-bytes': extra['xPaddingBytes'], + // 'sc-max-each-post-bytes': extra['scMaxEachPostBytes'], + // 'sc-min-posts-interval-ms': extra['scMinPostsIntervalMs'], + mode: params.mode, + ...proxy[`${proxy.network}-opts`], + }; + } else { + proxy._mode = params.mode; + } + } } if (params.encryption) { proxy.encryption = params.encryption; diff --git a/backend/src/core/proxy-utils/producers/clashmeta.js b/backend/src/core/proxy-utils/producers/clashmeta.js index d42798e8..fe433d9a 100644 --- a/backend/src/core/proxy-utils/producers/clashmeta.js +++ b/backend/src/core/proxy-utils/producers/clashmeta.js @@ -69,7 +69,10 @@ export default function ClashMeta_Producer() { proxy['reality-opts'])) ) { return false; - } else if (['xhttp'].includes(proxy.network)) { + } else if ( + !['vless'].includes(proxy.type) && + ['xhttp'].includes(proxy.network) + ) { return false; } return true; diff --git a/backend/src/core/proxy-utils/producers/sing-box.js b/backend/src/core/proxy-utils/producers/sing-box.js index 1d38628f..0587ef70 100644 --- a/backend/src/core/proxy-utils/producers/sing-box.js +++ b/backend/src/core/proxy-utils/producers/sing-box.js @@ -1026,6 +1026,10 @@ export default function singbox_Producer() { .produce(proxies, 'internal', { 'include-unsupported-proxy': true }) .map((proxy) => { try { + if (['xhttp'].includes(proxy.network)) + throw new Error( + `Platform sing-box does not support network: ${proxy.network}`, + ); switch (proxy.type) { case 'ssh': list.push(sshParser(proxy)); diff --git a/backend/src/core/proxy-utils/producers/uri.js b/backend/src/core/proxy-utils/producers/uri.js index 637eebc9..fdb1fdda 100644 --- a/backend/src/core/proxy-utils/producers/uri.js +++ b/backend/src/core/proxy-utils/producers/uri.js @@ -64,7 +64,14 @@ function vless(proxy) { extra = `&extra=${encodeURIComponent(proxy._extra)}`; } let mode = ''; - if (proxy._mode) { + if ( + ['xhttp'].includes(proxy.network) && + proxy[`${proxy.network}-opts`]?.mode + ) { + mode = `&mode=${encodeURIComponent( + proxy[`${proxy.network}-opts`].mode, + )}`; + } else if (proxy._mode) { mode = `&mode=${encodeURIComponent(proxy._mode)}`; } let pqv = ''; diff --git a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js index bbd71187..0c702b73 100644 --- a/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js +++ b/backend/src/test/proxy-parsers/v2ray-and-platforms.spec.js @@ -372,6 +372,36 @@ describe('VMess and VLESS parser coverage', function () { }); }); + it('parses xhttp VLESS shares with mihomo transport extras', function () { + const extra = JSON.stringify({ + noGRPCHeader: true, + xPaddingBytes: '64-128', + }); + const proxy = parseOne( + `vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(extra)}#VLESS%20XHTTP`, + ); + + expectSubset(proxy, { + type: 'vless', + name: 'VLESS XHTTP', + server: 'vless-xhttp.example.com', + port: 443, + uuid: UUID, + tls: true, + network: 'xhttp', + _extra: extra, + 'xhttp-opts': { + mode: 'stream-up', + path: '/xhttp', + headers: { + Host: 'cdn.example.com', + }, + 'no-grpc-header': true, + 'x-padding-bytes': '64-128', + }, + }); + }); + it('parses Shadowrocket VLESS shares', function () { const base = Base64.encode( `none:${UUID}@shadowrocket-vless.example.com:443`, diff --git a/backend/src/test/proxy-producers/structured.spec.js b/backend/src/test/proxy-producers/structured.spec.js index 8a78d33e..f611aab2 100644 --- a/backend/src/test/proxy-producers/structured.spec.js +++ b/backend/src/test/proxy-producers/structured.spec.js @@ -143,6 +143,59 @@ describe('Proxy structured producers', function () { }); }); + it('emits Mihomo VLESS xhttp proxies and preserves xhttp options', function () { + const proxy = { + type: 'vless', + name: 'XHTTP', + server: 'vless-xhttp.example.com', + port: 443, + uuid: UUID, + tls: true, + sni: 'sni.example.com', + network: 'xhttp', + 'xhttp-opts': { + path: '/xhttp', + headers: { + Host: 'cdn.example.com', + }, + mode: 'stream-up', + 'no-grpc-header': true, + 'x-padding-bytes': '64-128', + }, + _extra: JSON.stringify({ + noGRPCHeader: true, + xPaddingBytes: '64-128', + }), + }; + + const internal = produceInternal('Mihomo', proxy); + const external = loadProducedYaml('Mihomo', proxy); + + expect(internal).to.have.length(1); + expect(external.proxies).to.have.length(1); + expectSubset(internal[0], { + type: 'vless', + name: 'XHTTP', + network: 'xhttp', + servername: 'sni.example.com', + 'xhttp-opts': { + path: '/xhttp', + headers: { + Host: 'cdn.example.com', + }, + mode: 'stream-up', + 'no-grpc-header': true, + 'x-padding-bytes': '64-128', + }, + }); + expectSubset(external.proxies[0], { + type: 'vless', + name: 'XHTTP', + network: 'xhttp', + servername: 'sni.example.com', + }); + }); + it('normalizes Stash TUIC defaults and external yaml wrapper', function () { const proxy = { type: 'tuic', @@ -297,6 +350,28 @@ describe('Proxy structured producers', function () { }); }); + it('omits xhttp proxies from sing-box exports', function () { + const output = loadProducedJson('sing-box', { + type: 'vless', + name: 'XHTTP', + server: 'vless-xhttp.example.com', + port: 443, + uuid: UUID, + tls: true, + network: 'xhttp', + 'xhttp-opts': { + path: '/xhttp', + headers: { + Host: 'cdn.example.com', + }, + mode: 'stream-up', + }, + }); + + expect(output.outbounds).to.have.length(0); + expect(output.endpoints).to.have.length(0); + }); + it('stringifies JSON producer outputs as plain arrays', function () { const proxy = { type: 'http', diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index 352e527c..44755d02 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -211,6 +211,35 @@ describe('Proxy text producers', function () { ); }); + it('produces URI VLESS xhttp links with mihomo transport mode', function () { + const extra = JSON.stringify({ + noGRPCHeader: true, + xPaddingBytes: '64-128', + }); + const output = produceExternal('URI', { + type: 'vless', + name: 'URI XHTTP', + server: 'vless-xhttp.example.com', + port: 443, + uuid: UUID, + tls: true, + sni: 'sni.example.com', + network: 'xhttp', + _extra: extra, + 'xhttp-opts': { + path: '/xhttp', + headers: { + Host: 'cdn.example.com', + }, + mode: 'stream-up', + }, + }); + + expect(output).to.equal( + `vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&host=cdn.example.com&sni=sni.example.com&mode=stream-up&extra=${encodeURIComponent(extra)}#URI%20XHTTP`, + ); + }); + it('produces V2Ray exports as base64 encoded URI lists', function () { const output = produceExternal('V2Ray', { type: 'vless',