Skip to content

Commit b3d66d4

Browse files
committed
feat: 处理 clash 系和 sing-box 的 Early Data
1 parent 65cdaa0 commit b3d66d4

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
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.19.86",
3+
"version": "2.19.87",
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ 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);
147+
}
148+
}
137149
if (proxy['plugin-opts']?.tls) {
138150
if (isPresent(proxy, 'skip-cert-verify')) {
139151
proxy['plugin-opts']['skip-cert-verify'] =

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ 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+
proxy['ws-opts'].path = path;
207+
if (ed !== '') {
208+
proxy['ws-opts']['early-data-header-name'] =
209+
'Sec-WebSocket-Protocol';
210+
proxy['ws-opts']['max-early-data'] = parseInt(ed, 10);
211+
}
212+
}
201213

202214
if (proxy['plugin-opts']?.tls) {
203215
if (isPresent(proxy, 'skip-cert-verify')) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ 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);
179+
}
180+
}
169181
if (proxy['plugin-opts']?.tls) {
170182
if (isPresent(proxy, 'skip-cert-verify')) {
171183
proxy['plugin-opts']['skip-cert-verify'] =

backend/src/core/proxy-utils/producers/sing-box.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ const smuxParser = (smux, proxy) => {
7171
const wsParser = (proxy, parsedProxy) => {
7272
const transport = { type: 'ws', headers: {} };
7373
if (proxy['ws-opts']) {
74-
const { path: wsPath = '', headers: wsHeaders = {} } = proxy['ws-opts'];
74+
const {
75+
path: wsPath = '',
76+
headers: wsHeaders = {},
77+
'max-early-data': max_early_data,
78+
'early-data-header-name': early_data_header_name,
79+
} = proxy['ws-opts'];
80+
transport.early_data_header_name = early_data_header_name;
81+
transport.max_early_data = parseInt(max_early_data, 10);
7582
if (wsPath !== '') transport.path = `${wsPath}`;
7683
if (Object.keys(wsHeaders).length > 0) {
7784
const headers = {};

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ 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);
251+
}
252+
}
241253
if (proxy['plugin-opts']?.tls) {
242254
if (isPresent(proxy, 'skip-cert-verify')) {
243255
proxy['plugin-opts']['skip-cert-verify'] =

0 commit comments

Comments
 (0)