Skip to content

Commit d073dfe

Browse files
committed
feat: 支持 Trojan, VMess, VLESS httpupgrade(暂不支持 Shadowsocks v2ray-plugin)
1 parent f970ea3 commit d073dfe

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

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.14.307",
3+
"version": "2.14.308",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
55
"main": "src/main.js",
66
"scripts": {

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Base64 } from 'js-base64';
1616
// Parse SS URI format (only supports new SIP002, legacy format is depreciated).
1717
// reference: https://github.com/shadowsocks/shadowsocks-org/wiki/SIP002-URI-Scheme
1818
function URI_SS() {
19+
// TODO: 暂不支持 httpupgrade
1920
const name = 'URI SS Parser';
2021
const test = (line) => {
2122
return /^ss:\/\//.test(line);
@@ -299,6 +300,7 @@ function URI_VMess() {
299300
if (proxy.tls && proxy.sni) {
300301
proxy.sni = params.sni;
301302
}
303+
let httpupgrade = false;
302304
// handle obfs
303305
if (params.net === 'ws' || params.obfs === 'websocket') {
304306
proxy.network = 'ws';
@@ -309,6 +311,12 @@ function URI_VMess() {
309311
proxy.network = 'http';
310312
} else if (['grpc'].includes(params.net)) {
311313
proxy.network = 'grpc';
314+
} else if (
315+
params.net === 'httpupgrade' ||
316+
proxy.network === 'httpupgrade'
317+
) {
318+
proxy.network = 'ws';
319+
httpupgrade = true;
312320
}
313321
if (proxy.network) {
314322
let transportHost = params.host ?? params.obfsParam;
@@ -341,10 +349,15 @@ function URI_VMess() {
341349
'_grpc-type': getIfNotBlank(params.type),
342350
};
343351
} else {
344-
proxy[`${proxy.network}-opts`] = {
352+
const opts = {
345353
path: getIfNotBlank(transportPath),
346354
headers: { Host: getIfNotBlank(transportHost) },
347355
};
356+
if (httpupgrade) {
357+
opts['v2ray-http-upgrade'] = true;
358+
opts['v2ray-http-upgrade-fast-open'] = true;
359+
}
360+
proxy[`${proxy.network}-opts`] = opts;
348361
}
349362
} else {
350363
delete proxy.network;
@@ -444,10 +457,13 @@ function URI_VLESS() {
444457
proxy[`${params.security}-opts`] = opts;
445458
}
446459
}
447-
460+
let httpupgrade = false;
448461
proxy.network = params.type;
449462
if (proxy.network === 'tcp' && params.headerType === 'http') {
450463
proxy.network = 'http';
464+
} else if (proxy.network === 'httpupgrade') {
465+
proxy.network = 'ws';
466+
httpupgrade = true;
451467
}
452468
if (!proxy.network && isShadowrocket && params.obfs) {
453469
proxy.network = params.obfs;
@@ -485,6 +501,10 @@ function URI_VLESS() {
485501
if (['grpc'].includes(proxy.network)) {
486502
opts['_grpc-type'] = params.mode || 'gun';
487503
}
504+
if (httpupgrade) {
505+
opts['v2ray-http-upgrade'] = true;
506+
opts['v2ray-http-upgrade-fast-open'] = true;
507+
}
488508
if (Object.keys(opts).length > 0) {
489509
proxy[`${proxy.network}-opts`] = opts;
490510
}

backend/src/core/proxy-utils/parsers/peggy/trojan-uri.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ params = "?" head:param tail:("&"@param)* {
8989
}
9090
9191
if (params["type"]) {
92+
let httpupgrade
9293
proxy.network = params["type"]
94+
if(proxy.network === 'httpupgrade') {
95+
proxy.network = 'ws'
96+
httpupgrade = true
97+
}
9398
if (['grpc'].includes(proxy.network)) {
9499
proxy[proxy.network + '-opts'] = {
95100
'grpc-service-name': params["serviceName"],
@@ -102,6 +107,10 @@ params = "?" head:param tail:("&"@param)* {
102107
if (params["host"]) {
103108
$set(proxy, proxy.network+"-opts.headers.Host", decodeURIComponent(params["host"]));
104109
}
110+
if (httpupgrade) {
111+
$set(proxy, proxy.network+"-opts.v2ray-http-upgrade", true);
112+
$set(proxy, proxy.network+"-opts.v2ray-http-upgrade-fast-open", true);
113+
}
105114
}
106115
}
107116

backend/src/core/proxy-utils/parsers/peggy/trojan-uri.peg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ params = "?" head:param tail:("&"@param)* {
8787
}
8888

8989
if (params["type"]) {
90+
let httpupgrade
9091
proxy.network = params["type"]
92+
if(proxy.network === 'httpupgrade') {
93+
proxy.network = 'ws'
94+
httpupgrade = true
95+
}
9196
if (['grpc'].includes(proxy.network)) {
9297
proxy[proxy.network + '-opts'] = {
9398
'grpc-service-name': params["serviceName"],
@@ -100,6 +105,10 @@ params = "?" head:param tail:("&"@param)* {
100105
if (params["host"]) {
101106
$set(proxy, proxy.network+"-opts.headers.Host", decodeURIComponent(params["host"]));
102107
}
108+
if (httpupgrade) {
109+
$set(proxy, proxy.network+"-opts.v2ray-http-upgrade", true);
110+
$set(proxy, proxy.network+"-opts.v2ray-http-upgrade-fast-open", true);
111+
}
103112
}
104113
}
105114

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export default function URI_Producer() {
8484
if (proxy.network === 'http') {
8585
net = 'tcp';
8686
type = 'http';
87+
} else if (
88+
proxy.network === 'ws' &&
89+
proxy['ws-opts']?.['v2ray-http-upgrade']
90+
) {
91+
net = 'httpupgrade';
8792
}
8893
result = {
8994
v: '2',
@@ -172,9 +177,15 @@ export default function URI_Producer() {
172177
if (proxy.flow) {
173178
flow = `&flow=${encodeURIComponent(proxy.flow)}`;
174179
}
175-
let vlessTransport = `&type=${encodeURIComponent(
176-
proxy.network,
177-
)}`;
180+
let vlessType = proxy.network;
181+
if (
182+
proxy.network === 'ws' &&
183+
proxy['ws-opts']?.['v2ray-http-upgrade']
184+
) {
185+
vlessType = 'httpupgrade';
186+
}
187+
188+
let vlessTransport = `&type=${encodeURIComponent(vlessType)}`;
178189
if (['grpc'].includes(proxy.network)) {
179190
// https://github.com/XTLS/Xray-core/issues/91
180191
vlessTransport += `&mode=${encodeURIComponent(
@@ -220,7 +231,14 @@ export default function URI_Producer() {
220231
case 'trojan':
221232
let trojanTransport = '';
222233
if (proxy.network) {
223-
trojanTransport = `&type=${proxy.network}`;
234+
let trojanType = proxy.network;
235+
if (
236+
proxy.network === 'ws' &&
237+
proxy['ws-opts']?.['v2ray-http-upgrade']
238+
) {
239+
trojanType = 'httpupgrade';
240+
}
241+
trojanTransport = `&type=${encodeURIComponent(trojanType)}`;
224242
if (['grpc'].includes(proxy.network)) {
225243
let trojanTransportServiceName =
226244
proxy[`${proxy.network}-opts`]?.[

0 commit comments

Comments
 (0)