whistle 2.10.11 → 2.10.13

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.
@@ -896,13 +896,15 @@ module.exports = function init(_proxy) {
896
896
  var data = {};
897
897
  var count = options.count;
898
898
  var startTime = options.startTime;
899
+ var dumpCount = options.dumpCount;
900
+ var hasDump = dumpCount > 0;
899
901
  var clearNetwork =
900
- !(options.dumpCount > 0) && (count == 0 || startTime == -2);
902
+ !hasDump && (count == 0 || startTime == -2);
901
903
  if (!clearNetwork) {
902
904
  count = count > 0 && count < COUNT ? +count : COUNT;
903
- if (options.dumpCount > 0) {
905
+ if (hasDump) {
904
906
  var len = ids.length;
905
- startTime = ids[len > options.dumpCount ? len - options.dumpCount : 0];
907
+ startTime = ids[len > dumpCount ? len - dumpCount : 0];
906
908
  }
907
909
  }
908
910
  if (key && value) {
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 (isString(field)) {
345
- body = body && body[field];
346
- } else {
347
- body = body && body['dist-tags'];
348
- body = body && body['latest'];
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
  }
@@ -728,6 +731,21 @@ var simpleHostname = '';
728
731
  var cpus = os.cpus();
729
732
  var addressList = [];
730
733
  var usiTimer;
734
+ var clientIpMap = new Map();
735
+ var clientIpList;
736
+
737
+ exports.getClientIpList = function() {
738
+ clientIpList = clientIpList || Array.from(clientIpMap.keys());
739
+ return clientIpList;
740
+ };
741
+
742
+ exports.addClientIp = function(ip) {
743
+ if (clientIpMap.has(ip) && clientIpMap.size > 1) {
744
+ clientIpMap.delete(ip);
745
+ }
746
+ clientIpMap.set(ip, 1);
747
+ clientIpList = null;
748
+ };
731
749
 
732
750
  function updateServerInfo() {
733
751
  serverInfo = {ipv4: [], ipv6: []};
@@ -750,6 +768,14 @@ function updateSysInfo() {
750
768
  common.walkInterfaces(function (info) {
751
769
  addressList.push(info.address.toLowerCase());
752
770
  });
771
+ var excess = clientIpMap.size - 2000;
772
+ if (excess > 0) {
773
+ clientIpList = null;
774
+ var iter = clientIpMap.keys();
775
+ while (excess-- > 0) {
776
+ clientIpMap.delete(iter.next().value);
777
+ }
778
+ }
753
779
  usiTimer = setTimeout(updateSysInfo, 36000);
754
780
  }
755
781
 
@@ -1505,7 +1531,7 @@ function isText(type) {
1505
1531
 
1506
1532
  exports.isText = isText;
1507
1533
 
1508
- function supportHtmlTransform(res, req) {
1534
+ exports.supportHtmlTransform = function (res, req) {
1509
1535
  var headers = res.headers;
1510
1536
  if (getContentType(headers) != 'HTML' || !hasBody(res, req)) {
1511
1537
  return false;
@@ -1513,15 +1539,17 @@ function supportHtmlTransform(res, req) {
1513
1539
 
1514
1540
  var contentEncoding = getContentEncoding(headers);
1515
1541
  //chrome新增了sdch压缩算法,对此类响应无法解码,deflate无法区分deflate还是deflateRaw
1516
- return !contentEncoding || contentEncoding == 'gzip' || contentEncoding === 'br';
1517
- }
1518
-
1519
- exports.supportHtmlTransform = supportHtmlTransform;
1542
+ return !contentEncoding || contentEncoding == 'gzip' || contentEncoding === 'br' ||
1543
+ contentEncoding === 'zstd';
1544
+ };
1520
1545
 
1521
1546
  exports.getEnableEncoding = function(enable) {
1522
1547
  if (!enable) {
1523
1548
  return;
1524
1549
  }
1550
+ if (enable.zstd) {
1551
+ return supportsZstd ? 'zstd' : null;
1552
+ }
1525
1553
  if (enable.br) {
1526
1554
  return supportsBr ? 'br' : null;
1527
1555
  }
@@ -1546,7 +1574,8 @@ function removeUnsupportsHeaders(headers, supportsDeflate) {
1546
1574
  var acceptEncoding = [];
1547
1575
  for (var i = 0, len = list.length; i < len; i++) {
1548
1576
  var ae = list[i].toLowerCase();
1549
- if (ae && ((supportsDeflate && ae == 'deflate') || ae == 'gzip' || (supportsBr && ae === 'br'))) {
1577
+ if (ae && ((supportsDeflate && ae == 'deflate') || ae == 'gzip' || (supportsBr && ae === 'br') ||
1578
+ (supportsZstd && ae === 'zstd'))) {
1550
1579
  acceptEncoding.push(ae);
1551
1580
  }
1552
1581
  }
@@ -1567,6 +1596,8 @@ function getZipStream(headers) {
1567
1596
  return supportsBr && zlib.createBrotliCompress();
1568
1597
  case 'deflate':
1569
1598
  return zlib.createDeflate();
1599
+ case 'zstd':
1600
+ return supportsZstd && zlib.createZstdCompress();
1570
1601
  }
1571
1602
  }
1572
1603
 
@@ -1577,6 +1608,10 @@ exports.isZip = function(encoding, chunk) {
1577
1608
  if (encoding === 'br') {
1578
1609
  return supportsBr;
1579
1610
  }
1611
+ // zstd frame magic: 0x28 B5 2F FD
1612
+ if (encoding === 'zstd') {
1613
+ return supportsZstd;
1614
+ }
1580
1615
  return encoding === 'deflate';
1581
1616
  };
1582
1617
 
@@ -15,6 +15,13 @@ module.exports = function (url) {
15
15
  var search = urlMatch[4] || '';
16
16
  var hash = urlMatch[5] || null;
17
17
  var port = null;
18
+ var auth = null;
19
+ // user:password@ belongs to auth, not to the host (as in url.parse)
20
+ var atIndex = host.lastIndexOf('@');
21
+ if (atIndex !== -1) {
22
+ auth = decodeAuth(host.substring(0, atIndex));
23
+ host = host.substring(atIndex + 1);
24
+ }
18
25
  var hostname = host;
19
26
  var hostMatch = HOST_RE.exec(host);
20
27
  if (hostMatch) {
@@ -25,7 +32,7 @@ module.exports = function (url) {
25
32
  return {
26
33
  protocol: protocol,
27
34
  slashes: true,
28
- auth: null,
35
+ auth: auth,
29
36
  host: host,
30
37
  port: port,
31
38
  hostname: formatHost(hostname),
@@ -38,4 +45,12 @@ module.exports = function (url) {
38
45
  };
39
46
  };
40
47
 
48
+ function decodeAuth(auth) {
49
+ try {
50
+ return decodeURIComponent(auth);
51
+ } catch (e) {
52
+ return auth;
53
+ }
54
+ }
55
+
41
56
  module.exports.formatHost = formatHost;
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
- procData.cpuPercent = cpuElap.toFixed(1) + '%';
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 = cpuElap.toFixed(1) + '%';
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.11",
4
+ "version": "2.10.13",
5
5
  "dataDirname": ".whistle",
6
6
  "localUIHost": "local.whistlejs.com",
7
7
  "port": 8899,
@@ -51,7 +51,7 @@
51
51
  "lru-cache": "^4.1.1",
52
52
  "mime": "^1.6.0",
53
53
  "multer2": "^1.1.1",
54
- "node-forge": "^1.4.0",
54
+ "node-forge": "^1.4.1",
55
55
  "node-pac": "^0.5.1",
56
56
  "parseurl": "^1.3.1",
57
57
  "pfork": "^0.6.3",