whistle 2.10.8 → 2.10.10

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/assets/js/log.js CHANGED
@@ -243,6 +243,10 @@
243
243
  var cacheList = [];
244
244
  var origin = (location.origin || (location.protocol + '//' + location.host)) + '/';
245
245
 
246
+ try {
247
+ LOG_ID = decodeURIComponent(LOG_ID);
248
+ } catch(e) {}
249
+
246
250
  function setLog() {
247
251
  if (!cacheList.length) {
248
252
  return;
package/bin/api.js CHANGED
@@ -139,7 +139,8 @@ exports.network = {
139
139
  * - `Font`:字体文件
140
140
  * - `Img`:图片资源
141
141
  * - `Media`:音视频媒体
142
- * - `WS`:WebSocket 帧数据
142
+ * - `WS`:WebSocket 请求
143
+ * - `SSE`:Server-Sent Events 请求
143
144
  * - `Tunnel`:隧道连接(如 WebSocket 升级)
144
145
  * - `Wasm`:WebAssembly 模块
145
146
  * - `Mock`:Mock 数据
@@ -526,7 +527,90 @@ function getTimings(session) {
526
527
  };
527
528
  }
528
529
 
530
+ var PATTERN_FIELDS = ['url', 'm', 'method', 'reqH', 'reqHeader', 'reqHeaders',
531
+ 'b', 'body', 'reqBody', 's', 'statusCode', 'status', 'resH', 'resHeader', 'resHeaders'];
532
+
533
+ function getHeaderKey(key) {
534
+ return !key || typeof key !== 'string' || /[^\w!#$%&'*+.^`|~-]/.test(key) ? '' : key.toLowerCase();
535
+ }
536
+
537
+ function createFilter(item, name, key) {
538
+ var protocol = (item.exclude ? 'ex' : 'in') + 'cludeFilter://';
539
+ name = name ? name + (key ? '.' : ':') : '';
540
+ key = key ? key + ':' : '';
541
+ return protocol + name + key + item.value;
542
+ }
543
+
544
+ function createPattern(list) {
545
+ if (!list) {
546
+ return '';
547
+ }
548
+ if (!Array.isArray(list)) {
549
+ list = [list];
550
+ }
551
+ var len = list.length;
552
+ if (!len) {
553
+ return '';
554
+ }
555
+ var result = [];
556
+ var urlPattern;
557
+ var key;
558
+ var add = function(item, name, key) {
559
+ var p = createFilter(item, name, key);
560
+ if (result.indexOf(p) === -1) {
561
+ result.push(p);
562
+ }
563
+ };
564
+ list.forEach(function(item) {
565
+ if (!item || !item.value || PATTERN_FIELDS.indexOf(item.name) === -1) {
566
+ return;
567
+ }
568
+ var value = item.value;
569
+ if (typeof value !== 'string') {
570
+ value = String(value);
571
+ }
572
+ if (/\s/.test(item.value)) {
573
+ return;
574
+ }
575
+ switch(item.name) {
576
+ case 'url':
577
+ if (urlPattern) {
578
+ add(item);
579
+ } else {
580
+ urlPattern = item.value;
581
+ }
582
+ return;
583
+ case 'm':
584
+ case 'method':
585
+ return add(item, 'm');
586
+ case 'reqH':
587
+ case 'reqHeader':
588
+ case 'reqHeaders':
589
+ key = getHeaderKey(item.key);
590
+ return key && add(item, 'reqH', key);
591
+ case 'b':
592
+ case 'body':
593
+ case 'reqBody':
594
+ return add(item, 'b');
595
+ case 's':
596
+ case 'statusCode':
597
+ case 'status':
598
+ return add(item, 's');
599
+ case 'resH':
600
+ case 'resHeader':
601
+ case 'resHeaders':
602
+ key = getHeaderKey(item.key);
603
+ return key && add(item, 'resH', key);
604
+ }
605
+ });
606
+ if (urlPattern || result.length) {
607
+ result.unshift(urlPattern || '*');
608
+ }
609
+ return result.join(' ');
610
+ }
611
+
529
612
  exports.utils = {
613
+ createPattern: createPattern,
530
614
  isUtf8: isUtf8,
531
615
  getText: getText,
532
616
  getUtf8Buf: getUtf8Buf,
package/bin/util.js CHANGED
@@ -193,7 +193,7 @@ exports.getBody = function (res, callback, isRaw) {
193
193
  res.on('data', function(data) {
194
194
  resBody.push(data);
195
195
  });
196
- res.on('end', function() {
196
+ res.once('end', function() {
197
197
  resBody = Buffer.concat(resBody);
198
198
  try {
199
199
  callback(null, isRaw ? resBody : JSON.parse(resBody.toString()));
package/bin/whistle.js CHANGED
@@ -199,7 +199,7 @@ if (cmd === 'root') {
199
199
  if (file) {
200
200
  root = path.join(root, file);
201
201
  }
202
- process.stdout.write(root);
202
+ console.log(root);
203
203
  } else if (cmd === 'status') {
204
204
  var all = argv[3] === '--all' || argv[3] === '-l';
205
205
  if (argv[3] === '-S') {
@@ -104,7 +104,7 @@ exports.getReqData = function(req, callback) {
104
104
  }
105
105
  });
106
106
  req.on('error', handleCb);
107
- req.on('end', function() {
107
+ req.once('end', function() {
108
108
  if (done) {
109
109
  return;
110
110
  }
@@ -6,21 +6,23 @@ module.exports = function(req, res) {
6
6
  var body = req.body;
7
7
  var list;
8
8
  var exists = values.exists(body.name);
9
- if (values.add(body.name, body.value, body.clientId) != null) {
10
- if (isGroup(body.name)) {
11
- if (body.focusName) {
12
- values.moveTo(body.name, body.focusName, body.clientId);
9
+ if (!exists || !body.graceful) {
10
+ if (values.add(body.name, body.value, body.clientId) != null) {
11
+ if (isGroup(body.name)) {
12
+ if (body.focusName) {
13
+ values.moveTo(body.name, body.focusName, body.clientId);
14
+ }
15
+ } else if (body.groupName) {
16
+ values.moveToGroup(body.name, body.groupName);
17
+ } else if (!exists) {
18
+ var group = values.getFirstGroup();
19
+ group && values.moveTo(body.name, group.name, body.clientId, null, true);
13
20
  }
14
- } else if (body.groupName) {
15
- values.moveToGroup(body.name, body.groupName);
16
- } else if (!exists) {
17
- var group = values.getFirstGroup();
18
- group && values.moveTo(body.name, group.name, body.clientId, null, true);
19
21
  }
20
- }
21
- if (req.body.recycleFilename) {
22
- recycleBin.remove(req.body.recycleFilename);
23
- list = recycleBin.list();
22
+ if (body.recycleFilename) {
23
+ recycleBin.remove(body.recycleFilename);
24
+ list = recycleBin.list();
25
+ }
24
26
  }
25
27
  res.json({
26
28
  ec: 0,
@@ -8,6 +8,6 @@
8
8
  </head>
9
9
  <body>
10
10
  <div id="container" class="main"></div>
11
- <script src="js/index.js?v=2.10.8"></script>
11
+ <script src="js/index.js?v=2.10.10"></script>
12
12
  </body>
13
13
  </html>