Skip to content

Commit e042ab8

Browse files
committed
feat: 完善 ws 传输层
1 parent 631c539 commit e042ab8

5 files changed

Lines changed: 77 additions & 44 deletions

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

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,25 @@ export default function Clash_Producer() {
134134
proxy['h2-opts'].headers.host = [host];
135135
}
136136
}
137-
if (proxy.network === 'ws') {
138-
const wsPath = proxy['ws-opts']?.path;
139-
const reg = /^(.*?)(?:\?ed=(\d+))?$/;
140-
// eslint-disable-next-line no-unused-vars
141-
const [_, path = '', ed = ''] = reg.exec(wsPath);
142-
proxy['ws-opts'].path = path;
143-
if (ed !== '') {
144-
proxy['ws-opts']['early-data-header-name'] =
145-
'Sec-WebSocket-Protocol';
146-
proxy['ws-opts']['max-early-data'] = parseInt(ed, 10);
137+
if (['ws'].includes(proxy.network)) {
138+
const networkPath = proxy[`${proxy.network}-opts`]?.path;
139+
if (networkPath) {
140+
const reg = /^(.*?)(?:\?ed=(\d+))?$/;
141+
// eslint-disable-next-line no-unused-vars
142+
const [_, path = '', ed = ''] = reg.exec(networkPath);
143+
proxy[`${proxy.network}-opts`].path = path;
144+
if (ed !== '') {
145+
proxy['ws-opts']['early-data-header-name'] =
146+
'Sec-WebSocket-Protocol';
147+
proxy['ws-opts']['max-early-data'] = parseInt(
148+
ed,
149+
10,
150+
);
151+
}
152+
} else {
153+
proxy[`${proxy.network}-opts`] =
154+
proxy[`${proxy.network}-opts`] || {};
155+
proxy[`${proxy.network}-opts`].path = '/';
147156
}
148157
}
149158
if (proxy['plugin-opts']?.tls) {

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,25 @@ export default function ClashMeta_Producer() {
198198
proxy['h2-opts'].headers.host = [host];
199199
}
200200
}
201-
if (proxy.network === 'ws') {
202-
const wsPath = proxy['ws-opts']?.path;
203-
const reg = /^(.*?)(?:\?ed=(\d+))?$/;
204-
// eslint-disable-next-line no-unused-vars
205-
const [_, path = '', ed = ''] = reg.exec(wsPath);
206-
if (!proxy['ws-opts']) {
207-
proxy['ws-opts'] = {};
208-
}
209-
proxy['ws-opts'].path = path;
210-
if (ed !== '') {
211-
proxy['ws-opts']['early-data-header-name'] =
212-
'Sec-WebSocket-Protocol';
213-
proxy['ws-opts']['max-early-data'] = parseInt(ed, 10);
201+
if (['ws'].includes(proxy.network)) {
202+
const networkPath = proxy[`${proxy.network}-opts`]?.path;
203+
if (networkPath) {
204+
const reg = /^(.*?)(?:\?ed=(\d+))?$/;
205+
// eslint-disable-next-line no-unused-vars
206+
const [_, path = '', ed = ''] = reg.exec(networkPath);
207+
proxy[`${proxy.network}-opts`].path = path;
208+
if (ed !== '') {
209+
proxy['ws-opts']['early-data-header-name'] =
210+
'Sec-WebSocket-Protocol';
211+
proxy['ws-opts']['max-early-data'] = parseInt(
212+
ed,
213+
10,
214+
);
215+
}
216+
} else {
217+
proxy[`${proxy.network}-opts`] =
218+
proxy[`${proxy.network}-opts`] || {};
219+
proxy[`${proxy.network}-opts`].path = '/';
214220
}
215221
}
216222

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,25 @@ export default function Shadowrocket_Producer() {
166166
proxy['h2-opts'].headers.host = [host];
167167
}
168168
}
169-
if (proxy.network === 'ws') {
170-
const wsPath = proxy['ws-opts']?.path;
171-
const reg = /^(.*?)(?:\?ed=(\d+))?$/;
172-
// eslint-disable-next-line no-unused-vars
173-
const [_, path = '', ed = ''] = reg.exec(wsPath);
174-
proxy['ws-opts'].path = path;
175-
if (ed !== '') {
176-
proxy['ws-opts']['early-data-header-name'] =
177-
'Sec-WebSocket-Protocol';
178-
proxy['ws-opts']['max-early-data'] = parseInt(ed, 10);
169+
if (['ws'].includes(proxy.network)) {
170+
const networkPath = proxy[`${proxy.network}-opts`]?.path;
171+
if (networkPath) {
172+
const reg = /^(.*?)(?:\?ed=(\d+))?$/;
173+
// eslint-disable-next-line no-unused-vars
174+
const [_, path = '', ed = ''] = reg.exec(networkPath);
175+
proxy[`${proxy.network}-opts`].path = path;
176+
if (ed !== '') {
177+
proxy['ws-opts']['early-data-header-name'] =
178+
'Sec-WebSocket-Protocol';
179+
proxy['ws-opts']['max-early-data'] = parseInt(
180+
ed,
181+
10,
182+
);
183+
}
184+
} else {
185+
proxy[`${proxy.network}-opts`] =
186+
proxy[`${proxy.network}-opts`] || {};
187+
proxy[`${proxy.network}-opts`].path = '/';
179188
}
180189
}
181190
if (proxy['plugin-opts']?.tls) {

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,25 @@ export default function Stash_Producer() {
238238
proxy['h2-opts'].headers.host = [host];
239239
}
240240
}
241-
if (proxy.network === 'ws') {
242-
const wsPath = proxy['ws-opts']?.path;
243-
const reg = /^(.*?)(?:\?ed=(\d+))?$/;
244-
// eslint-disable-next-line no-unused-vars
245-
const [_, path = '', ed = ''] = reg.exec(wsPath);
246-
proxy['ws-opts'].path = path;
247-
if (ed !== '') {
248-
proxy['ws-opts']['early-data-header-name'] =
249-
'Sec-WebSocket-Protocol';
250-
proxy['ws-opts']['max-early-data'] = parseInt(ed, 10);
241+
if (['ws'].includes(proxy.network)) {
242+
const networkPath = proxy[`${proxy.network}-opts`]?.path;
243+
if (networkPath) {
244+
const reg = /^(.*?)(?:\?ed=(\d+))?$/;
245+
// eslint-disable-next-line no-unused-vars
246+
const [_, path = '', ed = ''] = reg.exec(networkPath);
247+
proxy[`${proxy.network}-opts`].path = path;
248+
if (ed !== '') {
249+
proxy['ws-opts']['early-data-header-name'] =
250+
'Sec-WebSocket-Protocol';
251+
proxy['ws-opts']['max-early-data'] = parseInt(
252+
ed,
253+
10,
254+
);
255+
}
256+
} else {
257+
proxy[`${proxy.network}-opts`] =
258+
proxy[`${proxy.network}-opts`] || {};
259+
proxy[`${proxy.network}-opts`].path = '/';
251260
}
252261
}
253262
if (proxy['plugin-opts']?.tls) {

0 commit comments

Comments
 (0)