whistle 2.10.11 → 2.10.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/biz/webui/htdocs/index.html +1 -1
- package/biz/webui/htdocs/js/index.js +27 -27
- package/lib/https/h2.js +10 -6
- package/lib/https/index.js +0 -2
- package/lib/index.js +1 -1
- package/lib/inspectors/res.js +3 -3
- package/lib/plugins/proxy.js +1 -5
- package/lib/rules/rules.js +19 -17
- package/lib/rules/util.js +2 -4
- package/lib/service/composer.js +0 -2
- package/lib/tunnel.js +8 -8
- package/lib/util/common.js +5 -1
- package/lib/util/index.js +23 -11
- package/lib/util/perf.js +3 -2
- package/lib/util/zlib.js +13 -1
- package/package.json +1 -1
package/lib/https/h2.js
CHANGED
|
@@ -469,12 +469,16 @@ exports.request = function (req, res, callback) {
|
|
|
469
469
|
if (err || !socket || !isH2) {
|
|
470
470
|
return handleH2();
|
|
471
471
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
472
|
+
try {
|
|
473
|
+
getClient(req, socket, name, function(clt) {
|
|
474
|
+
if (!clt) {
|
|
475
|
+
socket = null;
|
|
476
|
+
}
|
|
477
|
+
handleH2(clt);
|
|
478
|
+
});
|
|
479
|
+
} catch(e) {
|
|
480
|
+
handleH2();
|
|
481
|
+
}
|
|
478
482
|
},
|
|
479
483
|
req
|
|
480
484
|
);
|
package/lib/https/index.js
CHANGED
|
@@ -1290,8 +1290,6 @@ module.exports = function (socket, next, isWebPort) {
|
|
|
1290
1290
|
if (useSNI && socket._useSniAsTunnelDomain && useSNI !== socket.tunnelHostname) {
|
|
1291
1291
|
var tunnelPort = socket.tunnelPort || 443;
|
|
1292
1292
|
return common.connectInner({
|
|
1293
|
-
host: useSNI,
|
|
1294
|
-
port: tunnelPort,
|
|
1295
1293
|
proxyHost: config.host || LOCALHOST,
|
|
1296
1294
|
proxyPort: config.port,
|
|
1297
1295
|
headers: getTunnelHeaders(socket, statusLine, clientIp, clientPort, useSNI + ':' + tunnelPort)
|
package/lib/index.js
CHANGED
package/lib/inspectors/res.js
CHANGED
|
@@ -340,7 +340,7 @@ module.exports = function (req, res, next) {
|
|
|
340
340
|
if (util.isProxyPort(curServerPort) || util.isLocalPHost(req, isHttps)) {
|
|
341
341
|
headers[config.WEBUI_HEAD] = 1;
|
|
342
342
|
}
|
|
343
|
-
var clientId =
|
|
343
|
+
var clientId = headers[config.CLIENT_ID_HEADER];
|
|
344
344
|
if (clientId) {
|
|
345
345
|
proxyHeaders[config.CLIENT_ID_HEADER] = clientId;
|
|
346
346
|
}
|
|
@@ -753,8 +753,8 @@ module.exports = function (req, res, next) {
|
|
|
753
753
|
if (
|
|
754
754
|
req.method === 'DELETE' &&
|
|
755
755
|
(req._hasInjectBody ||
|
|
756
|
-
|
|
757
|
-
|
|
756
|
+
headers['transfer-encoding'] ||
|
|
757
|
+
headers['content-length'] > 0)
|
|
758
758
|
) {
|
|
759
759
|
req.useH2 = false;
|
|
760
760
|
}
|
package/lib/plugins/proxy.js
CHANGED
|
@@ -185,11 +185,7 @@ module.exports = function (options, cb) {
|
|
|
185
185
|
return socket;
|
|
186
186
|
};
|
|
187
187
|
var request = function (opts, cb) {
|
|
188
|
-
|
|
189
|
-
opts = { url: opts };
|
|
190
|
-
} else {
|
|
191
|
-
opts = extend({}, opts);
|
|
192
|
-
}
|
|
188
|
+
opts = typeof opts === 'string' ? { url: opts } : extend({}, opts);
|
|
193
189
|
opts.url = common.setProtocol(opts.url);
|
|
194
190
|
var uri = parseUrl(opts.url);
|
|
195
191
|
var client;
|
package/lib/rules/rules.js
CHANGED
|
@@ -898,9 +898,14 @@ function removePort(url) {
|
|
|
898
898
|
urlPath = url.substring(end);
|
|
899
899
|
url = url.substring(0, end);
|
|
900
900
|
}
|
|
901
|
-
end = url.indexOf('
|
|
901
|
+
end = url.indexOf(']', index);
|
|
902
902
|
if (end !== -1) {
|
|
903
|
-
url = url.substring(0, end);
|
|
903
|
+
url = url.substring(0, end).replace('[', '');
|
|
904
|
+
} else {
|
|
905
|
+
end = url.indexOf(':', index);
|
|
906
|
+
if (end !== -1 && url.indexOf('/', index + 1) === -1) {
|
|
907
|
+
url = url.substring(0, end);
|
|
908
|
+
}
|
|
904
909
|
}
|
|
905
910
|
return url + urlPath;
|
|
906
911
|
}
|
|
@@ -1068,11 +1073,7 @@ function resolveRuleList(req, list, vals, index, isFilter, isEnableProxy, host,
|
|
|
1068
1073
|
} else if (rule.isExact) {
|
|
1069
1074
|
matchedRes = pattern === url || pattern === curUrl;
|
|
1070
1075
|
if ((not ? !matchedRes : matchedRes) && checkFilter() && --index < 0) {
|
|
1071
|
-
if (
|
|
1072
|
-
(result = getExactRule(
|
|
1073
|
-
getRelativePath(pattern, curUrl, rule.matcher)
|
|
1074
|
-
))
|
|
1075
|
-
) {
|
|
1076
|
+
if (result = getExactRule(getRelativePath(pattern, curUrl, rule.matcher))) {
|
|
1076
1077
|
return result;
|
|
1077
1078
|
}
|
|
1078
1079
|
}
|
|
@@ -1103,7 +1104,7 @@ function resolveRuleList(req, list, vals, index, isFilter, isEnableProxy, host,
|
|
|
1103
1104
|
} else if (rule.isDomain && rule.lineProps.originUrl) {
|
|
1104
1105
|
filePath = '/';
|
|
1105
1106
|
}
|
|
1106
|
-
if (
|
|
1107
|
+
if (result = getPathRule()) {
|
|
1107
1108
|
return result;
|
|
1108
1109
|
}
|
|
1109
1110
|
}
|
|
@@ -1899,12 +1900,14 @@ function matchFilter(url, filter, req) {
|
|
|
1899
1900
|
}
|
|
1900
1901
|
|
|
1901
1902
|
var reqBody = req._reqBody;
|
|
1902
|
-
|
|
1903
|
+
var bodyPattern = filter.bodyPattern;
|
|
1904
|
+
var body = filter.body;
|
|
1905
|
+
if (bodyPattern || body) {
|
|
1903
1906
|
if (typeof reqBody !== 'string') {
|
|
1904
1907
|
return false;
|
|
1905
1908
|
}
|
|
1906
|
-
if (
|
|
1907
|
-
if (result =
|
|
1909
|
+
if (bodyPattern) {
|
|
1910
|
+
if (result = bodyPattern.exec(reqBody)) {
|
|
1908
1911
|
req._bodySubVals = [reqBody];
|
|
1909
1912
|
for (var i = 1, len = result.length; i < len; i++) {
|
|
1910
1913
|
req._bodySubVals[i] = (result[i] || '');
|
|
@@ -1912,9 +1915,7 @@ function matchFilter(url, filter, req) {
|
|
|
1912
1915
|
}
|
|
1913
1916
|
} else {
|
|
1914
1917
|
reqBody = reqBody.toLowerCase();
|
|
1915
|
-
result =
|
|
1916
|
-
reqBody.indexOf(filter.body.value) !== -1 ||
|
|
1917
|
-
reqBody.indexOf(filter.body.orgVal) !== -1;
|
|
1918
|
+
result = reqBody.indexOf(body.value) !== -1 || reqBody.indexOf(body.orgVal) !== -1;
|
|
1918
1919
|
}
|
|
1919
1920
|
|
|
1920
1921
|
return filter.not ? !result : result;
|
|
@@ -1932,13 +1933,14 @@ function matchFilter(url, filter, req) {
|
|
|
1932
1933
|
return true;
|
|
1933
1934
|
}
|
|
1934
1935
|
}
|
|
1936
|
+
var hPattern = filterVal.hPattern;
|
|
1935
1937
|
if (!value) {
|
|
1936
|
-
result = !
|
|
1938
|
+
result = !hPattern && !filterVal.value;
|
|
1937
1939
|
return true;
|
|
1938
1940
|
}
|
|
1939
1941
|
value = String(value);
|
|
1940
|
-
if (
|
|
1941
|
-
result =
|
|
1942
|
+
if (hPattern) {
|
|
1943
|
+
result = hPattern.test(value);
|
|
1942
1944
|
} else {
|
|
1943
1945
|
value = value.toLowerCase();
|
|
1944
1946
|
result =
|
package/lib/rules/util.js
CHANGED
|
@@ -72,18 +72,16 @@ if (config.networkMode && !config.shadowRulesMode) {
|
|
|
72
72
|
if (text) {
|
|
73
73
|
var file = (type || 'File: ') + name;
|
|
74
74
|
if (backRulesFirst && !type) {
|
|
75
|
-
text = resolveRemoteRules(reverseRules(text, file), file);
|
|
76
75
|
rulesList.unshift({
|
|
77
76
|
resolved: true,
|
|
78
77
|
file: file,
|
|
79
|
-
text: text
|
|
78
|
+
text: resolveRemoteRules(reverseRules(text, file), file)
|
|
80
79
|
});
|
|
81
80
|
} else {
|
|
82
|
-
text = resolveRemoteRules(handleInlineValues(text, file), file);
|
|
83
81
|
rulesList.push({
|
|
84
82
|
resolved: true,
|
|
85
83
|
file: file,
|
|
86
|
-
text: text
|
|
84
|
+
text: resolveRemoteRules(handleInlineValues(text, file), file)
|
|
87
85
|
});
|
|
88
86
|
}
|
|
89
87
|
}
|
package/lib/service/composer.js
CHANGED
|
@@ -149,8 +149,6 @@ function handleConnect(options, cb, count, testId) {
|
|
|
149
149
|
options = extend({}, origOpts);
|
|
150
150
|
}
|
|
151
151
|
common.connectInner({
|
|
152
|
-
host: options.hostname,
|
|
153
|
-
port: options.port || 443,
|
|
154
152
|
proxyHost: PROXY_OPTS.host,
|
|
155
153
|
proxyPort: PROXY_OPTS.port,
|
|
156
154
|
headers: options.headers
|
package/lib/tunnel.js
CHANGED
|
@@ -60,13 +60,13 @@ function tunnelProxy(server, proxy, type) {
|
|
|
60
60
|
var _parseUrl = function (_url, port) {
|
|
61
61
|
_url = _url || tunnelUrl;
|
|
62
62
|
options = req.options = parseUrl(_url);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
options.host
|
|
68
|
-
} else if (net.isIPv6(
|
|
69
|
-
options.host = '[' +
|
|
63
|
+
if (!options.port) {
|
|
64
|
+
var curHost = options.host || '';
|
|
65
|
+
options.port = port || 443;
|
|
66
|
+
if (curHost.indexOf(':') === -1) {
|
|
67
|
+
options.host = curHost + ':' + options.port;
|
|
68
|
+
} else if (net.isIPv6(curHost)) {
|
|
69
|
+
options.host = '[' + curHost + ']:' + options.port;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
return options;
|
|
@@ -427,7 +427,7 @@ function tunnelProxy(server, proxy, type) {
|
|
|
427
427
|
if (TUNNEL_RE.test(realUrl) && realUrl != tunnelUrl) {
|
|
428
428
|
_parseUrl(realUrl, isHttp ? 80 : 443);
|
|
429
429
|
tunnelUrl = 'tunnel://' + options.host;
|
|
430
|
-
data.realUrl =
|
|
430
|
+
data.realUrl = options.host;
|
|
431
431
|
}
|
|
432
432
|
}
|
|
433
433
|
originPort = options.port;
|
package/lib/util/common.js
CHANGED
|
@@ -62,6 +62,7 @@ var AUTH_RE = /^Basic /i;
|
|
|
62
62
|
var STREAM_OPTS = { highWaterMark: 1 };
|
|
63
63
|
var REAL_HOST_HEADER = 'x-whistle-real-host';
|
|
64
64
|
var supportsBr = zlib.createBrotliDecompress && zlib.createBrotliCompress;
|
|
65
|
+
var supportsZstd = zlib.createZstdDecompress && zlib.createZstdCompress;
|
|
65
66
|
var TIMEOUT_ERR = new Error('Timeout');
|
|
66
67
|
var noop = function () {};
|
|
67
68
|
var PATH_SEP_RE = /[\\/]/;
|
|
@@ -167,6 +168,7 @@ exports.CONN_TIMEOUT = CONN_TIMEOUT;
|
|
|
167
168
|
exports.TGZ_FILE_NAME_RE = /^(?:[\w.~-]+-)?whistle\.[a-z\d_-]+-\d+\.\d+\.\d+[\w.-]*\.(?:tgz|tar(?:\.gz)?)$/;
|
|
168
169
|
exports.parseUrl = parseUrl;
|
|
169
170
|
exports.supportsBr = supportsBr;
|
|
171
|
+
exports.supportsZstd = supportsZstd;
|
|
170
172
|
exports.SERVICE_HOST = 'admin.weso.pro';
|
|
171
173
|
exports.REMOTE_URL_RE = REMOTE_URL_RE;
|
|
172
174
|
exports.WHISTLE_PLUGIN_RE = WHISTLE_PLUGIN_RE;
|
|
@@ -1565,7 +1567,7 @@ function getContentEncoding(headers) {
|
|
|
1565
1567
|
(headers && headers['content-encoding']) || headers
|
|
1566
1568
|
);
|
|
1567
1569
|
return encoding === 'gzip' || (supportsBr && encoding === 'br') ||
|
|
1568
|
-
encoding === 'deflate' ? encoding : null;
|
|
1570
|
+
(supportsZstd && encoding === 'zstd') || encoding === 'deflate' ? encoding : null;
|
|
1569
1571
|
}
|
|
1570
1572
|
|
|
1571
1573
|
exports.getContentEncoding = getContentEncoding;
|
|
@@ -1579,6 +1581,8 @@ function getUnzipStream(headers) {
|
|
|
1579
1581
|
return supportsBr && zlib.createBrotliDecompress();
|
|
1580
1582
|
case 'deflate':
|
|
1581
1583
|
return zlib.createInflate();
|
|
1584
|
+
case 'zstd':
|
|
1585
|
+
return supportsZstd && zlib.createZstdDecompress();
|
|
1582
1586
|
}
|
|
1583
1587
|
}
|
|
1584
1588
|
|
package/lib/util/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var uid = config.uid;
|
|
|
32
32
|
var trimStr = common.trimStr;
|
|
33
33
|
var parseQuery = common.parseQuery;
|
|
34
34
|
var supportsBr = common.supportsBr;
|
|
35
|
+
var supportsZstd = common.supportsZstd;
|
|
35
36
|
var isLocalIp = common.isLocalIp;
|
|
36
37
|
var getStat = common.getStat;
|
|
37
38
|
var toBuffer = common.toBuffer;
|
|
@@ -341,11 +342,13 @@ exports.getLatestVersion = function(registry, cb, field) {
|
|
|
341
342
|
responseType: 'json'
|
|
342
343
|
},
|
|
343
344
|
function (_, body) {
|
|
344
|
-
if (
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
345
|
+
if (body) {
|
|
346
|
+
if (isString(field)) {
|
|
347
|
+
body = body[field];
|
|
348
|
+
} else {
|
|
349
|
+
body = body['dist-tags'];
|
|
350
|
+
body = body && body['latest'];
|
|
351
|
+
}
|
|
349
352
|
}
|
|
350
353
|
cb(body);
|
|
351
354
|
}
|
|
@@ -1505,7 +1508,7 @@ function isText(type) {
|
|
|
1505
1508
|
|
|
1506
1509
|
exports.isText = isText;
|
|
1507
1510
|
|
|
1508
|
-
function
|
|
1511
|
+
exports.supportHtmlTransform = function (res, req) {
|
|
1509
1512
|
var headers = res.headers;
|
|
1510
1513
|
if (getContentType(headers) != 'HTML' || !hasBody(res, req)) {
|
|
1511
1514
|
return false;
|
|
@@ -1513,15 +1516,17 @@ function supportHtmlTransform(res, req) {
|
|
|
1513
1516
|
|
|
1514
1517
|
var contentEncoding = getContentEncoding(headers);
|
|
1515
1518
|
//chrome新增了sdch压缩算法,对此类响应无法解码,deflate无法区分deflate还是deflateRaw
|
|
1516
|
-
return !contentEncoding || contentEncoding == 'gzip' || contentEncoding === 'br'
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
exports.supportHtmlTransform = supportHtmlTransform;
|
|
1519
|
+
return !contentEncoding || contentEncoding == 'gzip' || contentEncoding === 'br' ||
|
|
1520
|
+
contentEncoding === 'zstd';
|
|
1521
|
+
};
|
|
1520
1522
|
|
|
1521
1523
|
exports.getEnableEncoding = function(enable) {
|
|
1522
1524
|
if (!enable) {
|
|
1523
1525
|
return;
|
|
1524
1526
|
}
|
|
1527
|
+
if (enable.zstd) {
|
|
1528
|
+
return supportsZstd ? 'zstd' : null;
|
|
1529
|
+
}
|
|
1525
1530
|
if (enable.br) {
|
|
1526
1531
|
return supportsBr ? 'br' : null;
|
|
1527
1532
|
}
|
|
@@ -1546,7 +1551,8 @@ function removeUnsupportsHeaders(headers, supportsDeflate) {
|
|
|
1546
1551
|
var acceptEncoding = [];
|
|
1547
1552
|
for (var i = 0, len = list.length; i < len; i++) {
|
|
1548
1553
|
var ae = list[i].toLowerCase();
|
|
1549
|
-
if (ae && ((supportsDeflate && ae == 'deflate') || ae == 'gzip' || (supportsBr && ae === 'br')
|
|
1554
|
+
if (ae && ((supportsDeflate && ae == 'deflate') || ae == 'gzip' || (supportsBr && ae === 'br') ||
|
|
1555
|
+
(supportsZstd && ae === 'zstd'))) {
|
|
1550
1556
|
acceptEncoding.push(ae);
|
|
1551
1557
|
}
|
|
1552
1558
|
}
|
|
@@ -1567,6 +1573,8 @@ function getZipStream(headers) {
|
|
|
1567
1573
|
return supportsBr && zlib.createBrotliCompress();
|
|
1568
1574
|
case 'deflate':
|
|
1569
1575
|
return zlib.createDeflate();
|
|
1576
|
+
case 'zstd':
|
|
1577
|
+
return supportsZstd && zlib.createZstdCompress();
|
|
1570
1578
|
}
|
|
1571
1579
|
}
|
|
1572
1580
|
|
|
@@ -1577,6 +1585,10 @@ exports.isZip = function(encoding, chunk) {
|
|
|
1577
1585
|
if (encoding === 'br') {
|
|
1578
1586
|
return supportsBr;
|
|
1579
1587
|
}
|
|
1588
|
+
// zstd frame magic: 0x28 B5 2F FD
|
|
1589
|
+
if (encoding === 'zstd') {
|
|
1590
|
+
return supportsZstd;
|
|
1591
|
+
}
|
|
1580
1592
|
return encoding === 'deflate';
|
|
1581
1593
|
};
|
|
1582
1594
|
|
package/lib/util/perf.js
CHANGED
|
@@ -60,12 +60,13 @@ if (startTime !== false && startUsage !== false) {
|
|
|
60
60
|
var elapSystMS = secNSec2ms(elapUsage.system);
|
|
61
61
|
var cpuElap = (100 * (elapUserMS + elapSystMS)) / elapTimeMS;
|
|
62
62
|
var curTime = Date.now();
|
|
63
|
-
|
|
63
|
+
var cpuPercent = cpuElap.toFixed(1) + '%';
|
|
64
|
+
procData.cpuPercent = cpuPercent;
|
|
64
65
|
procData.memUsage = process.memoryUsage();
|
|
65
66
|
procData.updateTime = curTime;
|
|
66
67
|
if (cpuElap > maxCpuElap) {
|
|
67
68
|
maxCpuElap = cpuElap;
|
|
68
|
-
procData.maxCpu =
|
|
69
|
+
procData.maxCpu = cpuPercent;
|
|
69
70
|
procData.maxCpuTime = curTime;
|
|
70
71
|
}
|
|
71
72
|
if (procData.memUsage.rss > procData.maxRss) {
|
package/lib/util/zlib.js
CHANGED
|
@@ -53,6 +53,7 @@ var inflate = createConvenienceMethod(zlib.Inflate, false);
|
|
|
53
53
|
var gunzip = createConvenienceMethod(zlib.Gunzip, false);
|
|
54
54
|
var inflateRaw = createConvenienceMethod(zlib.InflateRaw, false);
|
|
55
55
|
var brotliDecompress = zlib.BrotliDecompress ? createConvenienceMethod(zlib.BrotliDecompress, false) : noop;
|
|
56
|
+
var zstdDecompress = zlib.ZstdDecompress ? createConvenienceMethod(zlib.ZstdDecompress, false) : noop;
|
|
56
57
|
|
|
57
58
|
function unzip(encoding, body, callback) {
|
|
58
59
|
if (body && typeof encoding === 'string') {
|
|
@@ -79,6 +80,15 @@ function unzip(encoding, body, callback) {
|
|
|
79
80
|
});
|
|
80
81
|
return;
|
|
81
82
|
}
|
|
83
|
+
if (encoding === 'zstd') {
|
|
84
|
+
limiter.push(function (done) {
|
|
85
|
+
zstdDecompress(body, function (err, data) {
|
|
86
|
+
done();
|
|
87
|
+
callback(err, data);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
82
92
|
if (encoding === 'deflate') {
|
|
83
93
|
limiter.push(function (done) {
|
|
84
94
|
inflate(body, function (err, data) {
|
|
@@ -102,5 +112,7 @@ module.exports = {
|
|
|
102
112
|
unzip: unzip,
|
|
103
113
|
inflate: inflate,
|
|
104
114
|
gunzip: gunzip,
|
|
105
|
-
inflateRaw: inflateRaw
|
|
115
|
+
inflateRaw: inflateRaw,
|
|
116
|
+
brotliDecompress: brotliDecompress,
|
|
117
|
+
zstdDecompress: zstdDecompress
|
|
106
118
|
};
|