Skip to content

Commit

Permalink
fix: vmess/vless http-opts.path/http-opts.headers.Host must be an arr…
Browse files Browse the repository at this point in the history
…ay in some clients
  • Loading branch information
xream committed Aug 21, 2023
1 parent 9e54507 commit 99b19c4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.14",
"version": "2.14.15",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions backend/src/core/proxy-utils/producers/clash.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ export default function Clash_Producer() {
}
}

if (
['vmess', 'vless'].includes(proxy.type) &&
proxy.network === 'http'
) {
let httpPath = proxy['http-opts']?.path;
if (
isPresent(proxy, 'http-opts.path') &&
!Array.isArray(httpPath)
) {
proxy['http-opts'].path = [httpPath];
}
let httpHost = proxy['http-opts']?.headers?.Host;
if (
isPresent(proxy, 'http-opts.headers.Host') &&
!Array.isArray(httpHost)
) {
proxy['http-opts'].headers.Host = [httpHost];
}
}

delete proxy['tls-fingerprint'];
return ' - ' + JSON.stringify(proxy) + '\n';
})
Expand Down
12 changes: 8 additions & 4 deletions backend/src/core/proxy-utils/producers/loon.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ function vmess(proxy) {
);
} else if (proxy.network === 'http') {
result.append(`,transport=http`);
let httpPath = proxy['http-opts']?.path;
let httpHost = proxy['http-opts']?.headers?.Host;
result.appendIfPresent(
`,path=${proxy['http-opts'].path}`,
`,path=${Array.isArray(httpPath) ? httpPath[0] : httpPath}`,
'http-opts.path',
);
result.appendIfPresent(
`,host=${proxy['http-opts'].headers.Host}`,
`,host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`,
'http-opts.headers.Host',
);
} else {
Expand Down Expand Up @@ -206,12 +208,14 @@ function vless(proxy) {
);
} else if (proxy.network === 'http') {
result.append(`,transport=http`);
let httpPath = proxy['http-opts']?.path;
let httpHost = proxy['http-opts']?.headers?.Host;
result.appendIfPresent(
`,path=${proxy['http-opts'].path}`,
`,path=${Array.isArray(httpPath) ? httpPath[0] : httpPath}`,
'http-opts.path',
);
result.appendIfPresent(
`,host=${proxy['http-opts'].headers.Host}`,
`,host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`,
'http-opts.headers.Host',
);
} else {
Expand Down
6 changes: 4 additions & 2 deletions backend/src/core/proxy-utils/producers/qx.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ function vmess(proxy) {
} else {
throw new Error(`network ${proxy.network} is unsupported`);
}
let httpPath = proxy[`${proxy.network}-opts`]?.path;
let httpHost = proxy[`${proxy.network}-opts`]?.headers?.Host;
appendIfPresent(
`,obfs-uri=${proxy[`${proxy.network}-opts`].path}`,
`,obfs-uri=${Array.isArray(httpPath) ? httpPath[0] : httpPath}`,
`${proxy.network}-opts.path`,
);
appendIfPresent(
`,obfs-host=${proxy[`${proxy.network}-opts`].headers.Host}`,
`,obfs-host=${Array.isArray(httpHost) ? httpHost[0] : httpHost}`,
`${proxy.network}-opts.headers.Host`,
);
} else {
Expand Down
20 changes: 20 additions & 0 deletions backend/src/core/proxy-utils/producers/stash.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ export default function Stash_Producer() {
}
}

if (
['vmess', 'vless'].includes(proxy.type) &&
proxy.network === 'http'
) {
let httpPath = proxy['http-opts']?.path;
if (
isPresent(proxy, 'http-opts.path') &&
!Array.isArray(httpPath)
) {
proxy['http-opts'].path = [httpPath];
}
let httpHost = proxy['http-opts']?.headers?.Host;
if (
isPresent(proxy, 'http-opts.headers.Host') &&
!Array.isArray(httpHost)
) {
proxy['http-opts'].headers.Host = [httpHost];
}
}

delete proxy['tls-fingerprint'];
return ' - ' + JSON.stringify(proxy) + '\n';
})
Expand Down

0 comments on commit 99b19c4

Please sign in to comment.