feat: mihomo 支持 XHTTP(详见 MetaCubeX/mihomo#2645)

This commit is contained in:
xream committed 2026-03-27 17:06:39 +08:00
1 parent cd42bbe6ea
commit a9debf0eaa
8 files changed
+175 -7

No files matched your search

+1 -1
View File
@@ -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": {
+24 -4
View File
@@ -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;
@@ -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;
@@ -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));
@@ -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 = '';
@@ -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`,
@@ -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',
@@ -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',