whistle 2.10.10 → 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/bin/api.js +1 -83
- package/bin/whistle.js +5 -0
- package/biz/webui/cgi-bin/get-data.js +0 -1
- package/biz/webui/cgi-bin/init.js +0 -1
- package/biz/webui/cgi-bin/status.js +2 -1
- package/biz/webui/htdocs/index.html +1 -1
- package/biz/webui/htdocs/js/index.js +49 -49
- package/index.js +10 -12
- package/lib/config.js +15 -66
- package/lib/https/ca.js +1 -1
- package/lib/https/h2.js +11 -7
- package/lib/https/index.js +111 -97
- package/lib/index.js +1 -1
- package/lib/inspectors/data.js +2 -0
- package/lib/inspectors/req.js +3 -6
- package/lib/inspectors/res.js +3 -6
- package/lib/plugins/index.js +1 -1
- package/lib/plugins/proxy.js +1 -5
- package/lib/rules/index.js +2 -1
- package/lib/rules/protocols.js +2 -4
- package/lib/rules/rules.js +21 -21
- package/lib/rules/util.js +2 -4
- package/lib/service/compose-data.js +2 -1
- package/lib/service/composer.js +5 -9
- package/lib/socket-mgr.js +4 -1
- package/lib/tunnel.js +17 -13
- package/lib/util/common.js +147 -13
- package/lib/util/index.js +42 -57
- package/lib/util/perf.js +3 -2
- package/lib/util/zlib.js +13 -1
- package/package.json +3 -3
package/lib/util/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var ReplacePatternTransform = require('./replace-pattern-transform');
|
|
|
24
24
|
var common = require('./common');
|
|
25
25
|
var proc = require('./process');
|
|
26
26
|
var parseUrl = require('./parse-url');
|
|
27
|
-
var h2Consts =
|
|
27
|
+
var h2Consts = require('http2').constants;
|
|
28
28
|
|
|
29
29
|
var protocols = protoMgr.protocols;
|
|
30
30
|
var resProtocols = protoMgr.resProtocols;
|
|
@@ -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;
|
|
@@ -39,7 +40,6 @@ var pendingFiles = {};
|
|
|
39
40
|
var localIpCache = new LRU({ max: 120 });
|
|
40
41
|
var LOCALHOST = '127.0.0.1';
|
|
41
42
|
var aliasProtocols = protoMgr.aliasProtocols;
|
|
42
|
-
var CONTEXT = vm.createContext();
|
|
43
43
|
var END_SLASH_RE = /[/\\]$/;
|
|
44
44
|
var GEN_URL_RE = /^\s*(?:https?:)?\/\/\w[^\s]*\s*$/i;
|
|
45
45
|
var CORS_KEY_RE = /^(?:enable|use-credentials|useCredentials|credentials)$/i;
|
|
@@ -50,17 +50,12 @@ var STYLE_START = toBuffer('<style>');
|
|
|
50
50
|
var STYLE_END = toBuffer('</style>');
|
|
51
51
|
var PROXY_RE = /^x?(?:socks|https?-proxy|proxy|internal(?:-https)?-proxy)$/;
|
|
52
52
|
var SEP_RE = /[|&]/;
|
|
53
|
-
var ctxTimer;
|
|
54
53
|
var END_RE = /[/\\]$/;
|
|
55
54
|
var EXPIRED_SEC = -123456;
|
|
56
55
|
var EXP_COOKIE = { maxAge: EXPIRED_SEC, path: '/' };
|
|
57
56
|
var EXP_SECURE_COOKIE = { maxAge: EXPIRED_SEC, path: '/', secure: true };
|
|
58
57
|
var EXP_COOKIE_D = { maxAge: EXPIRED_SEC, path: '/' };
|
|
59
58
|
var EXP_SECURE_COOKIE_D = { maxAge: EXPIRED_SEC, path: '/', secure: true };
|
|
60
|
-
var resetContext = function () {
|
|
61
|
-
ctxTimer = null;
|
|
62
|
-
CONTEXT = vm.createContext();
|
|
63
|
-
};
|
|
64
59
|
var TIMEOUT_ERR = common.TIMEOUT_ERR;
|
|
65
60
|
var SUB_MATCH_RE = /\$[&\d]/;
|
|
66
61
|
var PROTO_NAME_RE = /^([\w.-]+):\/\//;
|
|
@@ -89,6 +84,7 @@ var getMatcher = common.getMatcher;
|
|
|
89
84
|
var getMatcherValue = common.getMatcherValue;
|
|
90
85
|
var getRemoteAddr = common.getRemoteAddr;
|
|
91
86
|
var getRemotePort = common.getRemotePort;
|
|
87
|
+
var isRegExp = common.isRegExp;
|
|
92
88
|
var workerIndex = process.env && process.env.workerIndex;
|
|
93
89
|
var INTERNAL_ID = Date.now().toString(16) + Math.floor(Math.random() * 10000000).toString(16);
|
|
94
90
|
var pluginMgr;
|
|
@@ -175,6 +171,7 @@ exports.PLUGIN_INSPECTOR_CONFIG = Symbol('inspectorConfig');
|
|
|
175
171
|
exports.drain = require('./drain');
|
|
176
172
|
exports.isWin = process.platform === 'win32';
|
|
177
173
|
exports.isUtf8 = isUtf8;
|
|
174
|
+
exports.isRegExp = isRegExp;
|
|
178
175
|
exports.WhistleTransform = require('./whistle-transform');
|
|
179
176
|
exports.ReplacePatternTransform = ReplacePatternTransform;
|
|
180
177
|
exports.replacePattern = replacePattern;
|
|
@@ -345,11 +342,13 @@ exports.getLatestVersion = function(registry, cb, field) {
|
|
|
345
342
|
responseType: 'json'
|
|
346
343
|
},
|
|
347
344
|
function (_, body) {
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
345
|
+
if (body) {
|
|
346
|
+
if (isString(field)) {
|
|
347
|
+
body = body[field];
|
|
348
|
+
} else {
|
|
349
|
+
body = body['dist-tags'];
|
|
350
|
+
body = body && body['latest'];
|
|
351
|
+
}
|
|
353
352
|
}
|
|
354
353
|
cb(body);
|
|
355
354
|
}
|
|
@@ -425,7 +424,7 @@ exports.compare = compare;
|
|
|
425
424
|
var scriptCache = {};
|
|
426
425
|
var VM_OPTIONS = {
|
|
427
426
|
displayErrors: false,
|
|
428
|
-
timeout:
|
|
427
|
+
timeout: 72
|
|
429
428
|
};
|
|
430
429
|
var MAX_SCRIPT_SIZE = 1024 * 256;
|
|
431
430
|
var MAX_SCRIPT_CACHE_COUNT = 64;
|
|
@@ -471,34 +470,20 @@ function getScript(content) {
|
|
|
471
470
|
return script.script;
|
|
472
471
|
}
|
|
473
472
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
if (!ctxTimer) {
|
|
479
|
-
ctxTimer = setTimeout(resetContext, 30000);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
473
|
+
var customConsole = {};
|
|
474
|
+
['fatal', 'error', 'warn', 'info', 'log', 'debug'].forEach(function (level) {
|
|
475
|
+
customConsole[level] = logger[level];
|
|
476
|
+
});
|
|
482
477
|
|
|
483
|
-
exports.
|
|
478
|
+
exports.runInContext = function(script, context) {
|
|
484
479
|
try {
|
|
485
|
-
if (
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
level
|
|
489
|
-
) {
|
|
490
|
-
CONTEXT.console[level] = logger[level];
|
|
491
|
-
});
|
|
492
|
-
Object.keys(context).forEach(function (key) {
|
|
493
|
-
CONTEXT[key] = context[key];
|
|
494
|
-
});
|
|
495
|
-
script.runInContext(CONTEXT, VM_OPTIONS);
|
|
480
|
+
if (script = getScript(script)) {
|
|
481
|
+
context = Object.assign({ console: Object.create(customConsole) }, context);
|
|
482
|
+
script.runInNewContext(context, VM_OPTIONS);
|
|
496
483
|
}
|
|
497
484
|
return true;
|
|
498
485
|
} catch (e) {
|
|
499
486
|
logger.error(e);
|
|
500
|
-
} finally {
|
|
501
|
-
clearContext();
|
|
502
487
|
}
|
|
503
488
|
};
|
|
504
489
|
|
|
@@ -603,14 +588,6 @@ function formatDate(now) {
|
|
|
603
588
|
|
|
604
589
|
exports.formatDate = formatDate;
|
|
605
590
|
|
|
606
|
-
var REG_EXP_RE = /^\/(.+)\/(i?u?|ui)$/;
|
|
607
|
-
|
|
608
|
-
function isRegExp(regExp) {
|
|
609
|
-
return REG_EXP_RE.test(regExp);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
exports.isRegExp = isRegExp;
|
|
613
|
-
|
|
614
591
|
var ORIG_REG_EXP = /^\/(.+)\/([igmu]{0,4})$/;
|
|
615
592
|
var FLAGS_RE = /[igmu]{2}/;
|
|
616
593
|
|
|
@@ -723,14 +700,13 @@ function isAuthCapture(req) {
|
|
|
723
700
|
|
|
724
701
|
exports.isAuthCapture = isAuthCapture;
|
|
725
702
|
|
|
726
|
-
exports.toRegExp = function
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
regExp = null;
|
|
703
|
+
exports.toRegExp = function(regExp, ignoreCase) {
|
|
704
|
+
if (isRegExp(regExp)) {
|
|
705
|
+
try {
|
|
706
|
+
return new RegExp(RegExp.$1, ignoreCase ? 'i' : RegExp.$2);
|
|
707
|
+
} catch (e) {}
|
|
732
708
|
}
|
|
733
|
-
return
|
|
709
|
+
return null;
|
|
734
710
|
};
|
|
735
711
|
|
|
736
712
|
var isString = common.isString;
|
|
@@ -1532,7 +1508,7 @@ function isText(type) {
|
|
|
1532
1508
|
|
|
1533
1509
|
exports.isText = isText;
|
|
1534
1510
|
|
|
1535
|
-
function
|
|
1511
|
+
exports.supportHtmlTransform = function (res, req) {
|
|
1536
1512
|
var headers = res.headers;
|
|
1537
1513
|
if (getContentType(headers) != 'HTML' || !hasBody(res, req)) {
|
|
1538
1514
|
return false;
|
|
@@ -1540,15 +1516,17 @@ function supportHtmlTransform(res, req) {
|
|
|
1540
1516
|
|
|
1541
1517
|
var contentEncoding = getContentEncoding(headers);
|
|
1542
1518
|
//chrome新增了sdch压缩算法,对此类响应无法解码,deflate无法区分deflate还是deflateRaw
|
|
1543
|
-
return !contentEncoding || contentEncoding == 'gzip' || contentEncoding === 'br'
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
exports.supportHtmlTransform = supportHtmlTransform;
|
|
1519
|
+
return !contentEncoding || contentEncoding == 'gzip' || contentEncoding === 'br' ||
|
|
1520
|
+
contentEncoding === 'zstd';
|
|
1521
|
+
};
|
|
1547
1522
|
|
|
1548
1523
|
exports.getEnableEncoding = function(enable) {
|
|
1549
1524
|
if (!enable) {
|
|
1550
1525
|
return;
|
|
1551
1526
|
}
|
|
1527
|
+
if (enable.zstd) {
|
|
1528
|
+
return supportsZstd ? 'zstd' : null;
|
|
1529
|
+
}
|
|
1552
1530
|
if (enable.br) {
|
|
1553
1531
|
return supportsBr ? 'br' : null;
|
|
1554
1532
|
}
|
|
@@ -1573,7 +1551,8 @@ function removeUnsupportsHeaders(headers, supportsDeflate) {
|
|
|
1573
1551
|
var acceptEncoding = [];
|
|
1574
1552
|
for (var i = 0, len = list.length; i < len; i++) {
|
|
1575
1553
|
var ae = list[i].toLowerCase();
|
|
1576
|
-
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'))) {
|
|
1577
1556
|
acceptEncoding.push(ae);
|
|
1578
1557
|
}
|
|
1579
1558
|
}
|
|
@@ -1594,6 +1573,8 @@ function getZipStream(headers) {
|
|
|
1594
1573
|
return supportsBr && zlib.createBrotliCompress();
|
|
1595
1574
|
case 'deflate':
|
|
1596
1575
|
return zlib.createDeflate();
|
|
1576
|
+
case 'zstd':
|
|
1577
|
+
return supportsZstd && zlib.createZstdCompress();
|
|
1597
1578
|
}
|
|
1598
1579
|
}
|
|
1599
1580
|
|
|
@@ -1604,6 +1585,10 @@ exports.isZip = function(encoding, chunk) {
|
|
|
1604
1585
|
if (encoding === 'br') {
|
|
1605
1586
|
return supportsBr;
|
|
1606
1587
|
}
|
|
1588
|
+
// zstd frame magic: 0x28 B5 2F FD
|
|
1589
|
+
if (encoding === 'zstd') {
|
|
1590
|
+
return supportsZstd;
|
|
1591
|
+
}
|
|
1607
1592
|
return encoding === 'deflate';
|
|
1608
1593
|
};
|
|
1609
1594
|
|
|
@@ -2983,7 +2968,7 @@ exports.disableReqProps = function (req) {
|
|
|
2983
2968
|
delete headers['user-agent'];
|
|
2984
2969
|
}
|
|
2985
2970
|
|
|
2986
|
-
if (disable.gzip || isEnable(req, 'captureStream')) {
|
|
2971
|
+
if (disable.gzip || disable.zip || isEnable(req, 'captureStream')) {
|
|
2987
2972
|
delete headers['accept-encoding'];
|
|
2988
2973
|
}
|
|
2989
2974
|
|
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
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "whistle",
|
|
3
3
|
"description": "HTTP, HTTP2, HTTPS, Websocket debugging proxy",
|
|
4
|
-
"version": "2.10.
|
|
4
|
+
"version": "2.10.12",
|
|
5
5
|
"dataDirname": ".whistle",
|
|
6
6
|
"localUIHost": "local.whistlejs.com",
|
|
7
7
|
"port": 8899,
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"url": "https://github.com/avwo/whistle.git"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"adm-zip": "^0.6.
|
|
40
|
+
"adm-zip": "^0.6.1",
|
|
41
41
|
"async-limiter": "2.0.0",
|
|
42
42
|
"body-parser": "^1.20.6",
|
|
43
43
|
"colors": "1.1.2",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"docs": "vitepress build docs"
|
|
76
76
|
},
|
|
77
77
|
"engines": {
|
|
78
|
-
"node": ">=
|
|
78
|
+
"node": ">= 16.0.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"babel-core": "^6.7.6",
|