Skip to content

Commit 569f010

Browse files
committed
feat: 支持 Hysteria 2 URI ech 字段
1 parent fa4193e commit 569f010

5 files changed

Lines changed: 44 additions & 1 deletion

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.36.9",
3+
"version": "2.36.10",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"packageManager": "pnpm@11.0.9",

backend/src/core/proxy-utils/parsers/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,12 @@ function URI_Hysteria2() {
22492249
if (params.downmbps) {
22502250
proxy.down = params.downmbps;
22512251
}
2252+
const echOpts = buildMihomoEchOptsFromXrayFields({
2253+
echConfigList: params.ech,
2254+
});
2255+
if (echOpts) {
2256+
proxy['ech-opts'] = echOpts;
2257+
}
22522258

22532259
return proxy;
22542260
};

backend/src/core/proxy-utils/producers/uri.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,14 @@ export default function URI_Producer() {
12951295
if (proxy.tfo) {
12961296
hysteria2params.push(`fastopen=1`);
12971297
}
1298+
const hysteria2Ech = buildXrayEchConfigListFromMihomo(
1299+
proxy['ech-opts'],
1300+
);
1301+
if (hysteria2Ech) {
1302+
hysteria2params.push(
1303+
`ech=${encodeURIComponent(hysteria2Ech)}`,
1304+
);
1305+
}
12981306
result = `hysteria2://${encodeURIComponent(proxy.password)}@${
12991307
proxy.server
13001308
}:${proxy.port}?${hysteria2params.join(

backend/src/test/proxy-parsers/uri.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,17 @@ describe('Proxy URI parser coverage', function () {
531531
});
532532
});
533533

534+
it('parses Hysteria2 URI ech fields', function () {
535+
const proxy = parseOne(
536+
'hy2://hy2-secret@hy2.example.com:443?ech=ECHCONFIG#Hy2%20ECH',
537+
);
538+
539+
expect(proxy['ech-opts']).to.deep.equal({
540+
enable: true,
541+
config: 'ECHCONFIG',
542+
});
543+
});
544+
534545
it('rejects Hysteria2 salamander obfs without obfs-password', function () {
535546
const proxies = parseAll(
536547
'hy2://hy2-secret@hy2.example.com:443?obfs=salamander#Hy2%20Missing%20Password',

backend/src/test/proxy-producers/text.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,24 @@ describe('Proxy text producers', function () {
25812581
);
25822582
});
25832583

2584+
it('produces URI Hysteria2 links with ech from mihomo ech opts config', function () {
2585+
const output = produceExternal('URI', {
2586+
type: 'hysteria2',
2587+
name: 'URI Hysteria2 ECH',
2588+
server: 'hy2.example.com',
2589+
port: 443,
2590+
password: 'secret',
2591+
'ech-opts': {
2592+
enable: true,
2593+
config: 'ECHCONFIG',
2594+
},
2595+
});
2596+
2597+
expect(output).to.equal(
2598+
'hysteria2://secret@hy2.example.com:443?ech=ECHCONFIG#URI%20Hysteria2%20ECH',
2599+
);
2600+
});
2601+
25842602
it('matches mihomo ECH enable decoding when producing URI VLESS links', function () {
25852603
const baseProxy = {
25862604
type: 'vless',

0 commit comments

Comments
 (0)