mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 23:13:43 +00:00
feat: 升级 VLESS xHTTP 的解析/导出兼容性,支持 session-id 表达式字段并强化范围校验
- 新增 strict-positive range 归一化逻辑,xPaddingBytes、sc-max-each-post-bytes、session-length 改为严格正数/范围处理,边界行为更准确 - parser 与 producer 同步支持 sessionIDTable/sessionIDLength,兼容 xhttp 中 session-table/session-length 的双向映射 - 将会话位置/密钥字段名统一为 sessionIDPlacement/sessionIDKey,避免与旧字段冲突 - 保留 xhttp headers 中的空字符串值,修复 URI VLESS round-trip 时空 header 被丢弃的问题 - 增强不合法值降级到 `_extra_unsupported` 的处理,并补充 parser/producers 结构化与文本导出测试(含空表名、范围合法性、非法值过滤)
This commit is contained in:
7 files changed
+607
-117
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.24.10",
|
||||
"version": "2.24.11",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -22,7 +22,8 @@ import {
|
||||
normalizeXhttpIntegerValue,
|
||||
normalizeXhttpNonNegativeRange,
|
||||
normalizeXhttpPositiveRange,
|
||||
normalizeXhttpScalarUpperBound,
|
||||
normalizeXhttpStrictPositiveRangeString,
|
||||
normalizeXhttpStrictPositiveRangeValue,
|
||||
} from '../xhttp-utils';
|
||||
import { extractPathQueryParam, getPathQueryParam } from '../transport-path';
|
||||
import {
|
||||
@@ -952,7 +953,7 @@ function URI_VLESS() {
|
||||
|
||||
const parsedHeaders = {};
|
||||
for (const [key, value] of Object.entries(headers)) {
|
||||
if (typeof value === 'string' && value !== '') {
|
||||
if (typeof value === 'string') {
|
||||
parsedHeaders[key] = value;
|
||||
}
|
||||
}
|
||||
@@ -1023,7 +1024,7 @@ function URI_VLESS() {
|
||||
|
||||
const unsupportedHeaders = {};
|
||||
for (const [key, value] of Object.entries(headers)) {
|
||||
if (typeof value === 'string' && value !== '') {
|
||||
if (typeof value === 'string') {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1105,18 +1106,47 @@ function URI_VLESS() {
|
||||
}
|
||||
break;
|
||||
case 'xPaddingBytes':
|
||||
if (
|
||||
normalizeXhttpStrictPositiveRangeString(value) ==
|
||||
null
|
||||
) {
|
||||
setUnsupportedXhttpField(
|
||||
unsupportedExtra,
|
||||
key,
|
||||
value,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'xPaddingKey':
|
||||
case 'xPaddingHeader':
|
||||
case 'xPaddingPlacement':
|
||||
case 'xPaddingMethod':
|
||||
case 'uplinkHTTPMethod':
|
||||
case 'sessionIDPlacement':
|
||||
case 'sessionPlacement':
|
||||
case 'sessionIDKey':
|
||||
case 'sessionKey':
|
||||
case 'seqPlacement':
|
||||
case 'seqKey':
|
||||
case 'uplinkDataPlacement':
|
||||
case 'uplinkDataKey':
|
||||
if (!isNotBlank(value)) {
|
||||
if (typeof value !== 'string') {
|
||||
setUnsupportedXhttpField(
|
||||
unsupportedExtra,
|
||||
key,
|
||||
value,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'sessionIDTable':
|
||||
// NOTE: Xray-core and mihomo both validate this field
|
||||
// together with sessionIDLength when the table is
|
||||
// non-empty: the table must stay ASCII, the length
|
||||
// range must stay > 0, and the combined ID space must
|
||||
// remain large enough. We only do local shape checks
|
||||
// here for now, so type-valid values are not
|
||||
// automatically upstream-valid yet.
|
||||
if (typeof value !== 'string') {
|
||||
setUnsupportedXhttpField(
|
||||
unsupportedExtra,
|
||||
key,
|
||||
@@ -1134,7 +1164,10 @@ function URI_VLESS() {
|
||||
}
|
||||
break;
|
||||
case 'scMaxEachPostBytes':
|
||||
if (normalizeXhttpScalarUpperBound(value) == null) {
|
||||
if (
|
||||
normalizeXhttpStrictPositiveRangeString(value) ==
|
||||
null
|
||||
) {
|
||||
setUnsupportedXhttpField(
|
||||
unsupportedExtra,
|
||||
key,
|
||||
@@ -1151,6 +1184,23 @@ function URI_VLESS() {
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'sessionIDLength':
|
||||
// NOTE: Xray-core and mihomo treat this as a coupled
|
||||
// session-table/session-length constraint rather than a
|
||||
// standalone positive range. Keeping only the local
|
||||
// range normalization here does not guarantee the pair
|
||||
// will pass upstream validation.
|
||||
if (
|
||||
normalizeXhttpStrictPositiveRangeString(value) ==
|
||||
null
|
||||
) {
|
||||
setUnsupportedXhttpField(
|
||||
unsupportedExtra,
|
||||
key,
|
||||
value,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'xmux': {
|
||||
const unsupportedXmux = collectUnsupportedXmux(value);
|
||||
if (unsupportedXmux !== undefined) {
|
||||
@@ -1543,8 +1593,11 @@ function URI_VLESS() {
|
||||
if (extra.noGRPCHeader === true) {
|
||||
target['no-grpc-header'] = true;
|
||||
}
|
||||
if (isNotBlank(extra.xPaddingBytes)) {
|
||||
target['x-padding-bytes'] = extra.xPaddingBytes;
|
||||
const xPaddingBytes = normalizeXhttpStrictPositiveRangeString(
|
||||
extra.xPaddingBytes,
|
||||
);
|
||||
if (xPaddingBytes != null) {
|
||||
target['x-padding-bytes'] = xPaddingBytes;
|
||||
}
|
||||
if (extra.xPaddingObfsMode === true) {
|
||||
target['x-padding-obfs-mode'] = true;
|
||||
@@ -1564,12 +1617,27 @@ function URI_VLESS() {
|
||||
if (isNotBlank(extra.uplinkHTTPMethod)) {
|
||||
target['uplink-http-method'] = extra.uplinkHTTPMethod;
|
||||
}
|
||||
if (isNotBlank(extra.sessionPlacement)) {
|
||||
if (isNotBlank(extra.sessionIDPlacement)) {
|
||||
target['session-placement'] = extra.sessionIDPlacement;
|
||||
} else if (isNotBlank(extra.sessionPlacement)) {
|
||||
target['session-placement'] = extra.sessionPlacement;
|
||||
}
|
||||
if (isNotBlank(extra.sessionKey)) {
|
||||
if (isNotBlank(extra.sessionIDKey)) {
|
||||
target['session-key'] = extra.sessionIDKey;
|
||||
} else if (isNotBlank(extra.sessionKey)) {
|
||||
target['session-key'] = extra.sessionKey;
|
||||
}
|
||||
if (typeof extra.sessionIDTable === 'string') {
|
||||
target['session-table'] = extra.sessionIDTable;
|
||||
}
|
||||
|
||||
const sessionIDLength = normalizeXhttpStrictPositiveRangeString(
|
||||
extra.sessionIDLength,
|
||||
);
|
||||
if (sessionIDLength != null) {
|
||||
target['session-length'] = sessionIDLength;
|
||||
}
|
||||
|
||||
if (isNotBlank(extra.seqPlacement)) {
|
||||
target['seq-placement'] = extra.seqPlacement;
|
||||
}
|
||||
@@ -1590,7 +1658,7 @@ function URI_VLESS() {
|
||||
target['uplink-chunk-size'] = uplinkChunkSize;
|
||||
}
|
||||
|
||||
const scMaxEachPostBytes = normalizeXhttpScalarUpperBound(
|
||||
const scMaxEachPostBytes = normalizeXhttpStrictPositiveRangeValue(
|
||||
extra.scMaxEachPostBytes,
|
||||
);
|
||||
if (scMaxEachPostBytes != null) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
normalizeXhttpIntegerValue,
|
||||
normalizeXhttpNonNegativeRange,
|
||||
normalizeXhttpPositiveRange,
|
||||
normalizeXhttpScalarUpperBound,
|
||||
normalizeXhttpStrictPositiveRangeValue,
|
||||
} from '../xhttp-utils';
|
||||
import {
|
||||
extractPathQueryParam,
|
||||
@@ -27,7 +27,7 @@ function toStringHeaderMap(headers, { excludeHost = false } = {}) {
|
||||
|
||||
const parsedHeaders = {};
|
||||
for (const [key, value] of Object.entries(headers)) {
|
||||
if (typeof value !== 'string' || value === '') {
|
||||
if (typeof value !== 'string') {
|
||||
continue;
|
||||
}
|
||||
if (excludeHost && /^host$/i.test(key)) {
|
||||
@@ -209,10 +209,28 @@ function applyStructuredXhttpExtraFields(
|
||||
target.uplinkHTTPMethod = xhttpOpts['uplink-http-method'];
|
||||
}
|
||||
if (xhttpOpts['session-placement']) {
|
||||
target.sessionPlacement = xhttpOpts['session-placement'];
|
||||
target.sessionIDPlacement = xhttpOpts['session-placement'];
|
||||
}
|
||||
if (xhttpOpts['session-key']) {
|
||||
target.sessionKey = xhttpOpts['session-key'];
|
||||
target.sessionIDKey = xhttpOpts['session-key'];
|
||||
}
|
||||
if (typeof xhttpOpts['session-table'] === 'string') {
|
||||
// NOTE: This mirrors the current structured field mapping only.
|
||||
// Xray-core/mihomo still apply coupled validation with
|
||||
// session-length when the table is non-empty: ASCII-only table,
|
||||
// strictly positive length range, and enough total ID space.
|
||||
target.sessionIDTable = xhttpOpts['session-table'];
|
||||
}
|
||||
if (xhttpOpts['session-length'] != null) {
|
||||
// NOTE: The normalized range here is only a local serialization check.
|
||||
// Upstream compatibility still depends on the session-table/session-
|
||||
// length pair satisfying the extra Xray-core/mihomo constraints.
|
||||
const sessionIDLength = normalizeXhttpStrictPositiveRangeValue(
|
||||
xhttpOpts['session-length'],
|
||||
);
|
||||
if (sessionIDLength != null) {
|
||||
target.sessionIDLength = sessionIDLength;
|
||||
}
|
||||
}
|
||||
if (xhttpOpts['seq-placement']) {
|
||||
target.seqPlacement = xhttpOpts['seq-placement'];
|
||||
@@ -235,7 +253,7 @@ function applyStructuredXhttpExtraFields(
|
||||
}
|
||||
|
||||
if (xhttpOpts['sc-max-each-post-bytes'] != null) {
|
||||
const scMaxEachPostBytes = normalizeXhttpScalarUpperBound(
|
||||
const scMaxEachPostBytes = normalizeXhttpStrictPositiveRangeValue(
|
||||
xhttpOpts['sc-max-each-post-bytes'],
|
||||
);
|
||||
if (scMaxEachPostBytes != null) {
|
||||
@@ -526,9 +544,7 @@ function buildVlessExtra(proxy) {
|
||||
// structured Mihomo node so later edits are reflected on export, while
|
||||
// `_extra_unsupported` fills the holes needed for VLESS URI -> node ->
|
||||
// VLESS URI lossless round-trips. That also means supported-field format
|
||||
// conflicts are resolved by the structured emitters here, e.g.
|
||||
// sc-max-each-post-bytes still emits the compatibility upper bound while
|
||||
// sc-min-posts-interval-ms keeps range.
|
||||
// conflicts are resolved by the structured emitters here.
|
||||
const mergedExtra = mergeUnsupportedXhttpExtraObject(
|
||||
structuredExtra,
|
||||
proxy._extra_unsupported,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function parseNormalizedXhttpRangeBounds(
|
||||
value,
|
||||
{ allowZeroUpperBound = true } = {},
|
||||
{ allowZeroLowerBound = true, allowZeroUpperBound = true } = {},
|
||||
) {
|
||||
if (typeof value !== 'string' && typeof value !== 'number') {
|
||||
return undefined;
|
||||
@@ -22,9 +22,14 @@ function parseNormalizedXhttpRangeBounds(
|
||||
|
||||
const normalizedValue = `${value}`.trim();
|
||||
const rangeParts = normalizedValue.split('-');
|
||||
const minimumAllowedLowerBound = allowZeroLowerBound ? 0 : 1;
|
||||
const minimumAllowedUpperBound = allowZeroUpperBound ? 0 : 1;
|
||||
if (rangeParts.length === 1) {
|
||||
const normalizedInteger = parseUnsignedIntegerToken(rangeParts[0]);
|
||||
const minimumAllowedValue = allowZeroUpperBound ? 0 : 1;
|
||||
const minimumAllowedValue = Math.max(
|
||||
minimumAllowedLowerBound,
|
||||
minimumAllowedUpperBound,
|
||||
);
|
||||
return normalizedInteger >= minimumAllowedValue
|
||||
? {
|
||||
lowerBound: normalizedInteger,
|
||||
@@ -43,8 +48,9 @@ function parseNormalizedXhttpRangeBounds(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const minimumAllowedUpperBound = allowZeroUpperBound ? 0 : 1;
|
||||
return upperBound >= minimumAllowedUpperBound && upperBound >= lowerBound
|
||||
return lowerBound >= minimumAllowedLowerBound &&
|
||||
upperBound >= minimumAllowedUpperBound &&
|
||||
upperBound >= lowerBound
|
||||
? {
|
||||
lowerBound,
|
||||
upperBound,
|
||||
@@ -58,24 +64,14 @@ function parseNormalizedXhttpPositiveRangeBounds(value) {
|
||||
});
|
||||
}
|
||||
|
||||
export function normalizeXhttpScalarUpperBound(value) {
|
||||
// IMPORTANT: the legacy-client compatibility reason for collapsing ranges
|
||||
// to an upper bound specifically applies to sc-max-each-post-bytes.
|
||||
// Mihomo first shipped sc-max-each-post-bytes as an int-only field, then
|
||||
// only later added true range support, so emitting `lower-upper` here can
|
||||
// still break older clients that predate that change. Once the new
|
||||
// official Mihomo stable release with ranged sc-max-each-post-bytes is
|
||||
// broadly deployed, switch that field back to preserving full ranges and
|
||||
// remove the upper-bound compatibility logic tied to it.
|
||||
const normalizedBounds = parseNormalizedXhttpPositiveRangeBounds(value);
|
||||
return normalizedBounds?.upperBound;
|
||||
function parseNormalizedXhttpStrictPositiveRangeBounds(value) {
|
||||
return parseNormalizedXhttpRangeBounds(value, {
|
||||
allowZeroLowerBound: false,
|
||||
allowZeroUpperBound: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function normalizeXhttpPositiveRange(value) {
|
||||
// IMPORTANT: unlike sc-max-each-post-bytes, sc-min-posts-interval-ms does
|
||||
// not need an old-client compatibility shim. Mihomo introduced
|
||||
// sc-min-posts-interval-ms with range semantics from day one, so we should
|
||||
// keep exporting its full normalized range form instead of collapsing it.
|
||||
const normalizedBounds = parseNormalizedXhttpPositiveRangeBounds(value);
|
||||
if (!normalizedBounds) {
|
||||
return undefined;
|
||||
@@ -85,6 +81,26 @@ export function normalizeXhttpPositiveRange(value) {
|
||||
return lowerBound === upperBound ? upperBound : `${lowerBound}-${upperBound}`;
|
||||
}
|
||||
|
||||
export function normalizeXhttpStrictPositiveRangeString(value) {
|
||||
const normalizedBounds = parseNormalizedXhttpStrictPositiveRangeBounds(value);
|
||||
if (!normalizedBounds) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { lowerBound, upperBound } = normalizedBounds;
|
||||
return lowerBound === upperBound ? `${upperBound}` : `${lowerBound}-${upperBound}`;
|
||||
}
|
||||
|
||||
export function normalizeXhttpStrictPositiveRangeValue(value) {
|
||||
const normalizedBounds = parseNormalizedXhttpStrictPositiveRangeBounds(value);
|
||||
if (!normalizedBounds) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { lowerBound, upperBound } = normalizedBounds;
|
||||
return lowerBound === upperBound ? upperBound : `${lowerBound}-${upperBound}`;
|
||||
}
|
||||
|
||||
export function normalizeXhttpNonNegativeRange(value) {
|
||||
const normalizedBounds = parseNormalizedXhttpRangeBounds(value);
|
||||
if (!normalizedBounds) {
|
||||
|
||||
@@ -929,6 +929,8 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
xPaddingBytes: '64-128',
|
||||
scMaxEachPostBytes: 1000000,
|
||||
scMinPostsIntervalMs: 300,
|
||||
sessionIDTable: 'abcXYZ012',
|
||||
sessionIDLength: 16,
|
||||
xmux: {
|
||||
maxConnections: 0,
|
||||
maxConcurrency: '16-32',
|
||||
@@ -959,6 +961,8 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-max-each-post-bytes': 1000000,
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'session-table': 'abcXYZ012',
|
||||
'session-length': '16',
|
||||
'reuse-settings': {
|
||||
'max-connections': '0',
|
||||
'max-concurrency': '16-32',
|
||||
@@ -1014,9 +1018,11 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
host: 'download-host.example.com',
|
||||
noGRPCHeader: true,
|
||||
xPaddingBytes: '32-64',
|
||||
sessionIDTable: 'Base62',
|
||||
scMaxEachPostBytes: '500000-1000000',
|
||||
scMinPostsIntervalMs: '0-300',
|
||||
extra: {
|
||||
sessionIDLength: '8-12',
|
||||
xmux: {
|
||||
maxConnections: '8',
|
||||
hMaxReusableSecs: '900',
|
||||
@@ -1054,7 +1060,9 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
host: 'download-host.example.com',
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '32-64',
|
||||
'sc-max-each-post-bytes': 1000000,
|
||||
'session-table': 'Base62',
|
||||
'session-length': '8-12',
|
||||
'sc-max-each-post-bytes': '500000-1000000',
|
||||
'sc-min-posts-interval-ms': '0-300',
|
||||
'reuse-settings': {
|
||||
'max-connections': '8',
|
||||
@@ -1395,11 +1403,11 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('parses xhttp VLESS shares with Mihomo-style leading-zero sc scalars', function () {
|
||||
it('parses xhttp VLESS shares with Mihomo-style leading-zero sc values', function () {
|
||||
const extra = JSON.stringify({
|
||||
noGRPCHeader: true,
|
||||
xPaddingBytes: '64-128',
|
||||
scMaxEachPostBytes: '000-1000000',
|
||||
scMaxEachPostBytes: '000001-1000000',
|
||||
scMinPostsIntervalMs: '0300',
|
||||
downloadSettings: {
|
||||
address: 'download.example.com',
|
||||
@@ -1408,7 +1416,7 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
xhttpSettings: {
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
scMaxEachPostBytes: '000-1000000',
|
||||
scMaxEachPostBytes: '000001-1000000',
|
||||
scMinPostsIntervalMs: '000-300',
|
||||
},
|
||||
},
|
||||
@@ -1433,7 +1441,7 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
host: 'cdn.example.com',
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-max-each-post-bytes': 1000000,
|
||||
'sc-max-each-post-bytes': '1-1000000',
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'download-settings': {
|
||||
server: 'download.example.com',
|
||||
@@ -1441,14 +1449,14 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
tls: true,
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'sc-max-each-post-bytes': 1000000,
|
||||
'sc-max-each-post-bytes': '1-1000000',
|
||||
'sc-min-posts-interval-ms': '0-300',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('parses xhttp VLESS shares with Mihomo-style explicit-plus sc scalars', function () {
|
||||
it('parses xhttp VLESS shares with Mihomo-style explicit-plus sc values', function () {
|
||||
const extra = JSON.stringify({
|
||||
noGRPCHeader: true,
|
||||
xPaddingBytes: '64-128',
|
||||
@@ -1461,7 +1469,7 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
xhttpSettings: {
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
scMaxEachPostBytes: '+0-+1000000',
|
||||
scMaxEachPostBytes: '+1-+1000000',
|
||||
scMinPostsIntervalMs: '+0-+300',
|
||||
},
|
||||
},
|
||||
@@ -1486,7 +1494,7 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
host: 'cdn.example.com',
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-max-each-post-bytes': 1000000,
|
||||
'sc-max-each-post-bytes': '500000-1000000',
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'download-settings': {
|
||||
server: 'download.example.com',
|
||||
@@ -1494,7 +1502,7 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
tls: true,
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'sc-max-each-post-bytes': 1000000,
|
||||
'sc-max-each-post-bytes': '1-1000000',
|
||||
'sc-min-posts-interval-ms': '0-300',
|
||||
},
|
||||
},
|
||||
@@ -1623,6 +1631,102 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('parses empty xhttp VLESS session id tables as supported strings', function () {
|
||||
const extra = JSON.stringify({
|
||||
sessionIDTable: '',
|
||||
downloadSettings: {
|
||||
network: 'xhttp',
|
||||
xhttpSettings: {
|
||||
sessionIDTable: '',
|
||||
},
|
||||
},
|
||||
});
|
||||
const proxy = parseOne(
|
||||
`vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(
|
||||
extra,
|
||||
)}#VLESS%20XHTTP%20Empty%20Session%20Table`,
|
||||
);
|
||||
|
||||
expectSubset(proxy, {
|
||||
type: 'vless',
|
||||
server: 'vless-xhttp.example.com',
|
||||
port: 443,
|
||||
uuid: UUID,
|
||||
tls: true,
|
||||
network: 'xhttp',
|
||||
'xhttp-opts': {
|
||||
mode: 'stream-up',
|
||||
path: '/xhttp',
|
||||
host: 'cdn.example.com',
|
||||
'session-table': '',
|
||||
'download-settings': {
|
||||
network: 'xhttp',
|
||||
'session-table': '',
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(proxy).to.not.have.property('_extra');
|
||||
expect(proxy).to.not.have.property('_extra_unsupported');
|
||||
});
|
||||
|
||||
it('keeps invalid xhttp VLESS session id fields in _extra_unsupported', function () {
|
||||
const extra = JSON.stringify({
|
||||
sessionIDTable: 123,
|
||||
sessionIDLength: '0-32',
|
||||
downloadSettings: {
|
||||
network: 'xhttp',
|
||||
xhttpSettings: {
|
||||
sessionIDTable: false,
|
||||
extra: {
|
||||
sessionIDLength: '0-0',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const proxy = parseOne(
|
||||
`vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(
|
||||
extra,
|
||||
)}#VLESS%20XHTTP%20Invalid%20Session%20ID`,
|
||||
);
|
||||
|
||||
expectSubset(proxy, {
|
||||
type: 'vless',
|
||||
server: 'vless-xhttp.example.com',
|
||||
port: 443,
|
||||
uuid: UUID,
|
||||
tls: true,
|
||||
network: 'xhttp',
|
||||
'xhttp-opts': {
|
||||
mode: 'stream-up',
|
||||
path: '/xhttp',
|
||||
host: 'cdn.example.com',
|
||||
'download-settings': {
|
||||
network: 'xhttp',
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(proxy['xhttp-opts']).to.not.have.property('session-table');
|
||||
expect(proxy['xhttp-opts']).to.not.have.property('session-length');
|
||||
expect(
|
||||
proxy['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('session-table');
|
||||
expect(
|
||||
proxy['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('session-length');
|
||||
expect(proxy._extra_unsupported).to.deep.equal({
|
||||
sessionIDTable: 123,
|
||||
sessionIDLength: '0-32',
|
||||
downloadSettings: {
|
||||
xhttpSettings: {
|
||||
sessionIDTable: false,
|
||||
extra: {
|
||||
sessionIDLength: '0-0',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('parses extended xhttp VLESS extra fields and keeps unsupported fields in _extra_unsupported', function () {
|
||||
const extra = JSON.stringify({
|
||||
headers: {
|
||||
@@ -1787,6 +1891,123 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
).to.not.have.property('sockopt');
|
||||
});
|
||||
|
||||
it('normalizes xhttp VLESS extra field types from Xray JSON', function () {
|
||||
const extra = JSON.stringify({
|
||||
headers: {
|
||||
'X-Empty': '',
|
||||
'X-Number': 1,
|
||||
},
|
||||
noGRPCHeader: false,
|
||||
xPaddingBytes: 128,
|
||||
xPaddingObfsMode: false,
|
||||
xPaddingKey: '',
|
||||
xPaddingHeader: '',
|
||||
xPaddingPlacement: '',
|
||||
xPaddingMethod: '',
|
||||
uplinkHTTPMethod: '',
|
||||
sessionIDPlacement: 'header',
|
||||
sessionIDKey: 'X-Session-ID',
|
||||
sessionPlacement: 'query',
|
||||
sessionKey: 'legacy-session',
|
||||
seqPlacement: '',
|
||||
seqKey: '',
|
||||
uplinkDataPlacement: '',
|
||||
uplinkDataKey: '',
|
||||
downloadSettings: {
|
||||
network: 'xhttp',
|
||||
xhttpSettings: {
|
||||
headers: {
|
||||
'X-Download-Empty': '',
|
||||
},
|
||||
noGRPCHeader: false,
|
||||
xPaddingBytes: 32,
|
||||
xPaddingObfsMode: false,
|
||||
sessionIDPlacement: 'query',
|
||||
sessionIDKey: 'x_session_id',
|
||||
},
|
||||
},
|
||||
});
|
||||
const proxy = parseOne(
|
||||
`vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(
|
||||
extra,
|
||||
)}#VLESS%20XHTTP%20Typed%20Extra`,
|
||||
);
|
||||
|
||||
expectSubset(proxy, {
|
||||
type: 'vless',
|
||||
name: 'VLESS XHTTP Typed Extra',
|
||||
server: 'vless-xhttp.example.com',
|
||||
port: 443,
|
||||
uuid: UUID,
|
||||
tls: true,
|
||||
network: 'xhttp',
|
||||
'xhttp-opts': {
|
||||
mode: 'stream-up',
|
||||
path: '/xhttp',
|
||||
host: 'cdn.example.com',
|
||||
headers: {
|
||||
'X-Empty': '',
|
||||
},
|
||||
'x-padding-bytes': '128',
|
||||
'session-placement': 'header',
|
||||
'session-key': 'X-Session-ID',
|
||||
'download-settings': {
|
||||
network: 'xhttp',
|
||||
headers: {
|
||||
'X-Download-Empty': '',
|
||||
},
|
||||
'x-padding-bytes': '32',
|
||||
'session-placement': 'query',
|
||||
'session-key': 'x_session_id',
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(proxy['xhttp-opts']).to.not.have.property('no-grpc-header');
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'x-padding-obfs-mode',
|
||||
);
|
||||
expect(proxy['xhttp-opts']).to.not.have.property('x-padding-key');
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'x-padding-header',
|
||||
);
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'x-padding-placement',
|
||||
);
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'x-padding-method',
|
||||
);
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'uplink-http-method',
|
||||
);
|
||||
expect(proxy['xhttp-opts']).to.not.have.property('seq-placement');
|
||||
expect(proxy['xhttp-opts']).to.not.have.property('seq-key');
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'uplink-data-placement',
|
||||
);
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'uplink-data-key',
|
||||
);
|
||||
expect(
|
||||
proxy['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('no-grpc-header');
|
||||
expect(
|
||||
proxy['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('x-padding-obfs-mode');
|
||||
expect(proxy._extra_unsupported).to.deep.equal({
|
||||
headers: {
|
||||
'X-Number': 1,
|
||||
},
|
||||
noGRPCHeader: false,
|
||||
xPaddingObfsMode: false,
|
||||
downloadSettings: {
|
||||
xhttpSettings: {
|
||||
noGRPCHeader: false,
|
||||
xPaddingObfsMode: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('parses nested xhttp download TLS ECH DNS fields into mihomo sidecar fields', function () {
|
||||
const extra = JSON.stringify({
|
||||
downloadSettings: {
|
||||
@@ -1908,8 +2129,9 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
expect(proxy).to.not.have.property('_extra_unsupported');
|
||||
});
|
||||
|
||||
it('keeps malformed xhttp VLESS uplinkChunkSize values in _extra_unsupported', function () {
|
||||
it('keeps malformed xhttp VLESS range values in _extra_unsupported', function () {
|
||||
const extra = JSON.stringify({
|
||||
xPaddingBytes: 'fast',
|
||||
uplinkChunkSize: 'fast',
|
||||
downloadSettings: {
|
||||
address: 'download.example.com',
|
||||
@@ -1917,6 +2139,7 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
security: 'tls',
|
||||
xhttpSettings: {
|
||||
path: '/download',
|
||||
xPaddingBytes: 'faster',
|
||||
uplinkChunkSize: 'faster',
|
||||
},
|
||||
},
|
||||
@@ -1942,16 +2165,24 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'x-padding-bytes',
|
||||
);
|
||||
expect(proxy['xhttp-opts']).to.not.have.property(
|
||||
'uplink-chunk-size',
|
||||
);
|
||||
expect(
|
||||
proxy['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('x-padding-bytes');
|
||||
expect(
|
||||
proxy['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('uplink-chunk-size');
|
||||
expect(proxy._extra_unsupported).to.deep.equal({
|
||||
xPaddingBytes: 'fast',
|
||||
uplinkChunkSize: 'fast',
|
||||
downloadSettings: {
|
||||
xhttpSettings: {
|
||||
xPaddingBytes: 'faster',
|
||||
uplinkChunkSize: 'faster',
|
||||
},
|
||||
},
|
||||
@@ -2038,7 +2269,7 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
host: 'cdn.example.com',
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-max-each-post-bytes': 1000000,
|
||||
'sc-max-each-post-bytes': '500000-1000000',
|
||||
'reuse-settings': {
|
||||
'max-connections': '0',
|
||||
'max-concurrency': '16-32',
|
||||
@@ -2095,57 +2326,15 @@ describe('VMess and VLESS parser coverage', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('parses xhttp VLESS shares with zero-lower-bound scMaxEachPostBytes range', function () {
|
||||
const extra = JSON.stringify({
|
||||
noGRPCHeader: true,
|
||||
xPaddingBytes: '64-128',
|
||||
scMaxEachPostBytes: '0-1000000',
|
||||
xmux: {
|
||||
maxConnections: 0,
|
||||
maxConcurrency: '16-32',
|
||||
cMaxReuseTimes: '64-128',
|
||||
hMaxRequestTimes: '600-900',
|
||||
hMaxReusableSecs: '1800-3000',
|
||||
},
|
||||
});
|
||||
const proxy = parseOne(
|
||||
`vless://${UUID}@vless-xhttp.example.com:443?type=xhttp&security=tls&host=cdn.example.com&path=%2Fxhttp&mode=stream-up&extra=${encodeURIComponent(
|
||||
extra,
|
||||
)}#VLESS%20XHTTP%20Zero%20Lower%20Bound`,
|
||||
);
|
||||
|
||||
expectSubset(proxy, {
|
||||
type: 'vless',
|
||||
name: 'VLESS XHTTP Zero Lower Bound',
|
||||
server: 'vless-xhttp.example.com',
|
||||
port: 443,
|
||||
uuid: UUID,
|
||||
tls: true,
|
||||
network: 'xhttp',
|
||||
'xhttp-opts': {
|
||||
mode: 'stream-up',
|
||||
path: '/xhttp',
|
||||
host: 'cdn.example.com',
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-max-each-post-bytes': 1000000,
|
||||
'reuse-settings': {
|
||||
'max-connections': '0',
|
||||
'max-concurrency': '16-32',
|
||||
'c-max-reuse-times': '64-128',
|
||||
'h-max-request-times': '600-900',
|
||||
'h-max-reusable-secs': '1800-3000',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores invalid xhttp VLESS scMaxEachPostBytes values', function () {
|
||||
const invalidValues = [
|
||||
'1.5',
|
||||
1.5,
|
||||
'0',
|
||||
0,
|
||||
'0-1000000',
|
||||
'+0-+1000000',
|
||||
'000-1000000',
|
||||
'fast',
|
||||
'10-1',
|
||||
'9007199254740993',
|
||||
|
||||
@@ -1107,6 +1107,8 @@ describe('Proxy structured producers', function () {
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'session-table': 'Base62',
|
||||
'session-length': '16-32',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1129,6 +1131,8 @@ describe('Proxy structured producers', function () {
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'session-table': 'Base62',
|
||||
'session-length': '16-32',
|
||||
},
|
||||
});
|
||||
expectSubset(external.proxies[0], {
|
||||
@@ -1138,6 +1142,8 @@ describe('Proxy structured producers', function () {
|
||||
servername: 'sni.example.com',
|
||||
'xhttp-opts': {
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'session-table': 'Base62',
|
||||
'session-length': '16-32',
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -1214,6 +1220,8 @@ describe('Proxy structured producers', function () {
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'session-table': 'Base62',
|
||||
'session-length': '8-12',
|
||||
'reuse-settings': {
|
||||
'max-connections': '8',
|
||||
'h-max-reusable-secs': '900',
|
||||
@@ -1241,6 +1249,8 @@ describe('Proxy structured producers', function () {
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'session-table': 'Base62',
|
||||
'session-length': '8-12',
|
||||
'reuse-settings': {
|
||||
'max-connections': '8',
|
||||
'h-max-reusable-secs': '900',
|
||||
@@ -1262,6 +1272,8 @@ describe('Proxy structured producers', function () {
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'session-table': 'Base62',
|
||||
'session-length': '8-12',
|
||||
'reuse-settings': {
|
||||
'max-connections': '8',
|
||||
'h-max-reusable-secs': '900',
|
||||
|
||||
@@ -2647,6 +2647,8 @@ describe('Proxy text producers', function () {
|
||||
const extra = JSON.stringify({
|
||||
noGRPCHeader: true,
|
||||
xPaddingBytes: '64-128',
|
||||
sessionIDTable: 'Base62',
|
||||
sessionIDLength: 16,
|
||||
});
|
||||
const output = produceExternal('URI', {
|
||||
type: 'vless',
|
||||
@@ -2665,6 +2667,8 @@ describe('Proxy text producers', function () {
|
||||
mode: 'stream-up',
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '64-128',
|
||||
'session-table': 'Base62',
|
||||
'session-length': 16,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2675,6 +2679,41 @@ describe('Proxy text producers', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('produces URI VLESS xhttp links with explicit empty session table strings', function () {
|
||||
const extra = JSON.stringify({
|
||||
sessionIDTable: '',
|
||||
});
|
||||
const output = produceExternal('URI', {
|
||||
type: 'vless',
|
||||
name: 'URI XHTTP Empty Session Table',
|
||||
server: 'vless-xhttp.example.com',
|
||||
port: 443,
|
||||
uuid: UUID,
|
||||
tls: true,
|
||||
sni: 'sni.example.com',
|
||||
network: 'xhttp',
|
||||
'xhttp-opts': {
|
||||
path: '/xhttp',
|
||||
headers: {
|
||||
Host: 'cdn.example.com',
|
||||
},
|
||||
mode: 'stream-up',
|
||||
'session-table': '',
|
||||
},
|
||||
});
|
||||
|
||||
expect(output).to.equal(
|
||||
`vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&host=cdn.example.com&sni=sni.example.com&mode=stream-up&extra=${encodeURIComponent(
|
||||
extra,
|
||||
)}#URI%20XHTTP%20Empty%20Session%20Table`,
|
||||
);
|
||||
|
||||
const reparsed = ProxyUtils.parse(output);
|
||||
expect(reparsed, output).to.have.length(1);
|
||||
expect(reparsed[0]['xhttp-opts']?.['session-table']).to.equal('');
|
||||
expect(reparsed[0]).to.not.have.property('_extra_unsupported');
|
||||
});
|
||||
|
||||
it('preserves _extra_unsupported without letting it override structured xhttp fields when producing URI VLESS links', function () {
|
||||
const output = produceExternal('URI', {
|
||||
type: 'vless',
|
||||
@@ -2687,11 +2726,15 @@ describe('Proxy text producers', function () {
|
||||
network: 'xhttp',
|
||||
_extra_unsupported: {
|
||||
customField: 'keep-me',
|
||||
sessionIDTable: 'stale-table',
|
||||
downloadSettings: {
|
||||
sockopt: {
|
||||
mark: 255,
|
||||
},
|
||||
address: 'old.example.com',
|
||||
xhttpSettings: {
|
||||
sessionIDLength: '1-2',
|
||||
},
|
||||
},
|
||||
},
|
||||
'xhttp-opts': {
|
||||
@@ -2701,12 +2744,16 @@ describe('Proxy text producers', function () {
|
||||
Host: 'cdn.example.com',
|
||||
},
|
||||
'no-grpc-header': true,
|
||||
'session-table': 'Base62',
|
||||
'session-length': '16-32',
|
||||
'download-settings': {
|
||||
server: 'download.example.com',
|
||||
port: 8443,
|
||||
tls: true,
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'session-table': 'abcXYZ012',
|
||||
'session-length': '8-12',
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -2715,6 +2762,8 @@ describe('Proxy text producers', function () {
|
||||
const extra = JSON.parse(decodeURIComponent(encodedExtra));
|
||||
expect(extra.customField).to.equal('keep-me');
|
||||
expect(extra.noGRPCHeader).to.equal(true);
|
||||
expect(extra.sessionIDTable).to.equal('Base62');
|
||||
expect(extra.sessionIDLength).to.equal('16-32');
|
||||
expect(extra.downloadSettings?.address).to.equal(
|
||||
'download.example.com',
|
||||
);
|
||||
@@ -2730,12 +2779,34 @@ describe('Proxy text producers', function () {
|
||||
expect(extra.downloadSettings?.xhttpSettings?.host).to.equal(
|
||||
'download-host.example.com',
|
||||
);
|
||||
expect(extra.downloadSettings?.xhttpSettings?.sessionIDTable).to.equal(
|
||||
'abcXYZ012',
|
||||
);
|
||||
expect(extra.downloadSettings?.xhttpSettings?.sessionIDLength).to.equal(
|
||||
'8-12',
|
||||
);
|
||||
|
||||
const reparsed = ProxyUtils.parse(output);
|
||||
expect(reparsed, output).to.have.length(1);
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.server,
|
||||
).to.equal('download.example.com');
|
||||
expect(reparsed[0]['xhttp-opts']?.['session-table']).to.equal(
|
||||
'Base62',
|
||||
);
|
||||
expect(reparsed[0]['xhttp-opts']?.['session-length']).to.equal(
|
||||
'16-32',
|
||||
);
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'session-table'
|
||||
],
|
||||
).to.equal('abcXYZ012');
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'session-length'
|
||||
],
|
||||
).to.equal('8-12');
|
||||
expect(reparsed[0]._extra_unsupported).to.deep.equal({
|
||||
customField: 'keep-me',
|
||||
downloadSettings: {
|
||||
@@ -2750,6 +2821,8 @@ describe('Proxy text producers', function () {
|
||||
const rawExtra = JSON.stringify({
|
||||
customField: 'keep-me',
|
||||
scMinPostsIntervalMs: '0-300',
|
||||
sessionIDTable: 'raw-table',
|
||||
sessionIDLength: '8-12',
|
||||
});
|
||||
const output = produceExternal('URI', {
|
||||
type: 'vless',
|
||||
@@ -2768,6 +2841,8 @@ describe('Proxy text producers', function () {
|
||||
Host: 'cdn.example.com',
|
||||
},
|
||||
'sc-min-posts-interval-ms': 300,
|
||||
'session-table': 'structured-table',
|
||||
'session-length': '16-32',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2779,6 +2854,10 @@ describe('Proxy text producers', function () {
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['sc-min-posts-interval-ms'],
|
||||
).to.equal('0-300');
|
||||
expect(reparsed[0]['xhttp-opts']?.['session-table']).to.equal(
|
||||
'raw-table',
|
||||
);
|
||||
expect(reparsed[0]['xhttp-opts']?.['session-length']).to.equal('8-12');
|
||||
});
|
||||
|
||||
it('stringifies plain-object _extra before using it as the final xhttp URI extra', function () {
|
||||
@@ -3259,8 +3338,8 @@ describe('Proxy text producers', function () {
|
||||
xPaddingPlacement: 'header',
|
||||
xPaddingMethod: 'tokenish',
|
||||
uplinkHTTPMethod: 'PUT',
|
||||
sessionPlacement: 'query',
|
||||
sessionKey: 'x_session_id',
|
||||
sessionIDPlacement: 'query',
|
||||
sessionIDKey: 'x_session_id',
|
||||
seqPlacement: 'header',
|
||||
seqKey: 'X-Seq',
|
||||
uplinkDataPlacement: 'header',
|
||||
@@ -3297,8 +3376,8 @@ describe('Proxy text producers', function () {
|
||||
xPaddingPlacement: 'query',
|
||||
xPaddingMethod: 'repeat-x',
|
||||
uplinkHTTPMethod: 'PATCH',
|
||||
sessionPlacement: 'header',
|
||||
sessionKey: 'X-Session',
|
||||
sessionIDPlacement: 'header',
|
||||
sessionIDKey: 'X-Session',
|
||||
seqPlacement: 'query',
|
||||
seqKey: 'x_seq',
|
||||
uplinkDataPlacement: 'cookie',
|
||||
@@ -3419,9 +3498,9 @@ describe('Proxy text producers', function () {
|
||||
).to.equal(-1);
|
||||
});
|
||||
|
||||
it('normalizes Mihomo leading-zero structured xhttp scalars when producing URI VLESS links', function () {
|
||||
it('normalizes Mihomo leading-zero structured xhttp values when producing URI VLESS links', function () {
|
||||
const extra = JSON.stringify({
|
||||
scMaxEachPostBytes: 1000000,
|
||||
scMaxEachPostBytes: '1-1000000',
|
||||
scMinPostsIntervalMs: 300,
|
||||
downloadSettings: {
|
||||
address: 'download.example.com',
|
||||
@@ -3432,7 +3511,7 @@ describe('Proxy text producers', function () {
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
mode: 'stream-up',
|
||||
scMaxEachPostBytes: 1000000,
|
||||
scMaxEachPostBytes: '1-1000000',
|
||||
scMinPostsIntervalMs: '0-300',
|
||||
},
|
||||
},
|
||||
@@ -3452,7 +3531,7 @@ describe('Proxy text producers', function () {
|
||||
headers: {
|
||||
Host: 'cdn.example.com',
|
||||
},
|
||||
'sc-max-each-post-bytes': '000-1000000',
|
||||
'sc-max-each-post-bytes': '000001-1000000',
|
||||
'sc-min-posts-interval-ms': '0300',
|
||||
'download-settings': {
|
||||
server: 'download.example.com',
|
||||
@@ -3460,7 +3539,7 @@ describe('Proxy text producers', function () {
|
||||
tls: true,
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'sc-max-each-post-bytes': '000-1000000',
|
||||
'sc-max-each-post-bytes': '000001-1000000',
|
||||
'sc-min-posts-interval-ms': '000-300',
|
||||
},
|
||||
},
|
||||
@@ -3475,7 +3554,7 @@ describe('Proxy text producers', function () {
|
||||
const reparsed = ProxyUtils.parse(output);
|
||||
expect(reparsed, output).to.have.length(1);
|
||||
expect(reparsed[0]['xhttp-opts']?.['sc-max-each-post-bytes']).to.equal(
|
||||
1000000,
|
||||
'1-1000000',
|
||||
);
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['sc-min-posts-interval-ms'],
|
||||
@@ -3484,7 +3563,7 @@ describe('Proxy text producers', function () {
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'sc-max-each-post-bytes'
|
||||
],
|
||||
).to.equal(1000000);
|
||||
).to.equal('1-1000000');
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'sc-min-posts-interval-ms'
|
||||
@@ -3492,9 +3571,9 @@ describe('Proxy text producers', function () {
|
||||
).to.equal('0-300');
|
||||
});
|
||||
|
||||
it('normalizes Mihomo explicit-plus structured xhttp scalars when producing URI VLESS links', function () {
|
||||
it('normalizes Mihomo explicit-plus structured xhttp values when producing URI VLESS links', function () {
|
||||
const extra = JSON.stringify({
|
||||
scMaxEachPostBytes: 1000000,
|
||||
scMaxEachPostBytes: '500000-1000000',
|
||||
scMinPostsIntervalMs: 300,
|
||||
downloadSettings: {
|
||||
address: 'download.example.com',
|
||||
@@ -3505,7 +3584,7 @@ describe('Proxy text producers', function () {
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
mode: 'stream-up',
|
||||
scMaxEachPostBytes: 1000000,
|
||||
scMaxEachPostBytes: '1-1000000',
|
||||
scMinPostsIntervalMs: '0-300',
|
||||
},
|
||||
},
|
||||
@@ -3533,7 +3612,7 @@ describe('Proxy text producers', function () {
|
||||
tls: true,
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'sc-max-each-post-bytes': '+0-+1000000',
|
||||
'sc-max-each-post-bytes': '+1-+1000000',
|
||||
'sc-min-posts-interval-ms': '+0-+300',
|
||||
},
|
||||
},
|
||||
@@ -3548,7 +3627,7 @@ describe('Proxy text producers', function () {
|
||||
const reparsed = ProxyUtils.parse(output);
|
||||
expect(reparsed, output).to.have.length(1);
|
||||
expect(reparsed[0]['xhttp-opts']?.['sc-max-each-post-bytes']).to.equal(
|
||||
1000000,
|
||||
'500000-1000000',
|
||||
);
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['sc-min-posts-interval-ms'],
|
||||
@@ -3557,7 +3636,7 @@ describe('Proxy text producers', function () {
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'sc-max-each-post-bytes'
|
||||
],
|
||||
).to.equal(1000000);
|
||||
).to.equal('1-1000000');
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'sc-min-posts-interval-ms'
|
||||
@@ -4167,11 +4246,87 @@ describe('Proxy text producers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('preserves empty xhttp header values when round-tripping URI VLESS links', function () {
|
||||
const extra = JSON.stringify({
|
||||
headers: {
|
||||
'X-Empty': '',
|
||||
'X-Value': '1',
|
||||
},
|
||||
noGRPCHeader: false,
|
||||
xPaddingObfsMode: false,
|
||||
downloadSettings: {
|
||||
network: 'xhttp',
|
||||
xhttpSettings: {
|
||||
path: '/download',
|
||||
headers: {
|
||||
'X-Download-Empty': '',
|
||||
'X-Download': '1',
|
||||
},
|
||||
noGRPCHeader: false,
|
||||
xPaddingObfsMode: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
const input = `vless://${UUID}@vless-xhttp.example.com:443?security=tls&type=xhttp&path=%2Fxhttp&extra=${encodeURIComponent(
|
||||
extra,
|
||||
)}#URI%20XHTTP%20Empty%20Headers`;
|
||||
|
||||
const parsed = ProxyUtils.parse(input);
|
||||
expect(parsed, input).to.have.length(1);
|
||||
expect(parsed[0]['xhttp-opts']?.headers).to.deep.equal({
|
||||
'X-Empty': '',
|
||||
'X-Value': '1',
|
||||
});
|
||||
expect(
|
||||
parsed[0]['xhttp-opts']?.['download-settings']?.headers,
|
||||
).to.deep.equal({
|
||||
'X-Download-Empty': '',
|
||||
'X-Download': '1',
|
||||
});
|
||||
|
||||
const output = produceExternal('URI', parsed[0]);
|
||||
const [, encodedExtra] = output.match(/[?&]extra=([^#]+)/);
|
||||
const reparsedExtra = JSON.parse(decodeURIComponent(encodedExtra));
|
||||
expect(reparsedExtra.headers).to.deep.equal({
|
||||
'X-Empty': '',
|
||||
'X-Value': '1',
|
||||
});
|
||||
expect(reparsedExtra.noGRPCHeader).to.equal(false);
|
||||
expect(reparsedExtra.xPaddingObfsMode).to.equal(false);
|
||||
expect(
|
||||
reparsedExtra.downloadSettings?.xhttpSettings?.headers,
|
||||
).to.deep.equal({
|
||||
'X-Download-Empty': '',
|
||||
'X-Download': '1',
|
||||
});
|
||||
expect(
|
||||
reparsedExtra.downloadSettings?.xhttpSettings?.noGRPCHeader,
|
||||
).to.equal(false);
|
||||
expect(
|
||||
reparsedExtra.downloadSettings?.xhttpSettings?.xPaddingObfsMode,
|
||||
).to.equal(false);
|
||||
|
||||
const reparsed = ProxyUtils.parse(output);
|
||||
expect(reparsed, output).to.have.length(1);
|
||||
expect(reparsed[0]['xhttp-opts']?.headers).to.deep.equal({
|
||||
'X-Empty': '',
|
||||
'X-Value': '1',
|
||||
});
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.headers,
|
||||
).to.deep.equal({
|
||||
'X-Download-Empty': '',
|
||||
'X-Download': '1',
|
||||
});
|
||||
});
|
||||
|
||||
it('normalizes structured xhttp range-form scalars when producing URI VLESS links', function () {
|
||||
const extra = JSON.stringify({
|
||||
noGRPCHeader: true,
|
||||
xPaddingBytes: '64-128',
|
||||
scMaxEachPostBytes: 1000000,
|
||||
sessionIDTable: 'Base62',
|
||||
sessionIDLength: '16-32',
|
||||
scMaxEachPostBytes: '1-1000000',
|
||||
scMinPostsIntervalMs: '0-300',
|
||||
xmux: {
|
||||
maxConnections: '8',
|
||||
@@ -4185,7 +4340,9 @@ describe('Proxy text producers', function () {
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
mode: 'stream-up',
|
||||
scMaxEachPostBytes: 1000000,
|
||||
sessionIDTable: 'abcXYZ012',
|
||||
sessionIDLength: '8-12',
|
||||
scMaxEachPostBytes: '500000-1000000',
|
||||
scMinPostsIntervalMs: '0-300',
|
||||
extra: {
|
||||
xmux: {
|
||||
@@ -4212,7 +4369,9 @@ describe('Proxy text producers', function () {
|
||||
},
|
||||
'no-grpc-header': true,
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-max-each-post-bytes': '0-1000000',
|
||||
'session-table': 'Base62',
|
||||
'session-length': '16-32',
|
||||
'sc-max-each-post-bytes': '1-1000000',
|
||||
'sc-min-posts-interval-ms': '0-300',
|
||||
'reuse-settings': {
|
||||
'max-connections': '8',
|
||||
@@ -4223,6 +4382,8 @@ describe('Proxy text producers', function () {
|
||||
tls: true,
|
||||
path: '/download',
|
||||
host: 'download-host.example.com',
|
||||
'session-table': 'abcXYZ012',
|
||||
'session-length': '8-12',
|
||||
'sc-max-each-post-bytes': '500000 - 1000000',
|
||||
'sc-min-posts-interval-ms': '0 - 300',
|
||||
'reuse-settings': {
|
||||
@@ -4241,21 +4402,37 @@ describe('Proxy text producers', function () {
|
||||
const reparsed = ProxyUtils.parse(output);
|
||||
expect(reparsed, output).to.have.length(1);
|
||||
expect(reparsed[0]['xhttp-opts']?.['sc-max-each-post-bytes']).to.equal(
|
||||
1000000,
|
||||
'1-1000000',
|
||||
);
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['sc-min-posts-interval-ms'],
|
||||
).to.equal('0-300');
|
||||
expect(reparsed[0]['xhttp-opts']?.['session-table']).to.equal(
|
||||
'Base62',
|
||||
);
|
||||
expect(reparsed[0]['xhttp-opts']?.['session-length']).to.equal(
|
||||
'16-32',
|
||||
);
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'sc-max-each-post-bytes'
|
||||
],
|
||||
).to.equal(1000000);
|
||||
).to.equal('500000-1000000');
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'sc-min-posts-interval-ms'
|
||||
],
|
||||
).to.equal('0-300');
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'session-table'
|
||||
],
|
||||
).to.equal('abcXYZ012');
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings']?.[
|
||||
'session-length'
|
||||
],
|
||||
).to.equal('8-12');
|
||||
});
|
||||
|
||||
it('does not truncate malformed nested download port strings when producing URI VLESS links', function () {
|
||||
@@ -4357,6 +4534,7 @@ describe('Proxy text producers', function () {
|
||||
'x-padding-bytes': '64-128',
|
||||
'sc-max-each-post-bytes': '9007199254740993',
|
||||
'sc-min-posts-interval-ms': 0,
|
||||
'session-length': '0-32',
|
||||
'uplink-chunk-size': '64-fast',
|
||||
'reuse-settings': {
|
||||
'max-connections': '8',
|
||||
@@ -4371,6 +4549,7 @@ describe('Proxy text producers', function () {
|
||||
'x-padding-bytes': '32-64',
|
||||
'sc-max-each-post-bytes': '1-9007199254740993',
|
||||
'sc-min-posts-interval-ms': 'fast',
|
||||
'session-length': 0,
|
||||
'uplink-chunk-size': 'fast',
|
||||
'reuse-settings': {
|
||||
'max-concurrency': '16-32',
|
||||
@@ -4396,6 +4575,9 @@ describe('Proxy text producers', function () {
|
||||
expect(reparsed[0]['xhttp-opts']).to.not.have.property(
|
||||
'uplink-chunk-size',
|
||||
);
|
||||
expect(reparsed[0]['xhttp-opts']).to.not.have.property(
|
||||
'session-length',
|
||||
);
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('sc-max-each-post-bytes');
|
||||
@@ -4405,6 +4587,9 @@ describe('Proxy text producers', function () {
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('uplink-chunk-size');
|
||||
expect(
|
||||
reparsed[0]['xhttp-opts']?.['download-settings'],
|
||||
).to.not.have.property('session-length');
|
||||
});
|
||||
|
||||
it('omits top-level URI xhttp extra when only invalid structured scalars remain', function () {
|
||||
@@ -4425,6 +4610,8 @@ describe('Proxy text producers', function () {
|
||||
},
|
||||
'sc-max-each-post-bytes': '9007199254740993',
|
||||
'sc-min-posts-interval-ms': 0,
|
||||
'session-table': 123,
|
||||
'session-length': '0-32',
|
||||
'uplink-chunk-size': 'fast',
|
||||
},
|
||||
});
|
||||
@@ -4470,6 +4657,8 @@ describe('Proxy text producers', function () {
|
||||
tls: true,
|
||||
'sc-max-each-post-bytes': '1-9007199254740993',
|
||||
'sc-min-posts-interval-ms': 'fast',
|
||||
'session-table': false,
|
||||
'session-length': 0,
|
||||
'uplink-chunk-size': 'fast',
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user