whistle 2.9.100 → 2.9.101

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/README-en_US.md CHANGED
@@ -9,7 +9,7 @@
9
9
  [![node version](https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square)](http://nodejs.org/download/)
10
10
  [![npm download](https://img.shields.io/npm/dm/whistle.svg?style=flat-square)](https://npmjs.org/package/whistle)
11
11
  [![NPM count](https://img.shields.io/npm/dt/whistle.svg?style=flat-square)](https://www.npmjs.com/package/whistle)
12
- [![License](https://img.shields.io/aur/license/whistle?style=flat-square)](https://www.npmjs.com/package/whistle)
12
+ [![License](https://img.shields.io/github/license/avwo/whistle?style=flat-square)](https://www.npmjs.com/package/whistle)
13
13
 
14
14
  [中文](./README.md) · English
15
15
 
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  [![node version](https://img.shields.io/badge/node.js->=_8-green.svg?style=flat-square)](http://nodejs.org/download/)
11
11
  [![npm download](https://img.shields.io/npm/dm/whistle.svg?style=flat-square)](https://npmjs.org/package/whistle)
12
12
  [![NPM count](https://img.shields.io/npm/dt/whistle.svg?style=flat-square)](https://www.npmjs.com/package/whistle)
13
- [![License](https://img.shields.io/aur/license/whistle?style=flat-square)](https://www.npmjs.com/package/whistle)
13
+ [![License](https://img.shields.io/github/license/avwo/whistle?style=flat-square)](https://www.npmjs.com/package/whistle)
14
14
 
15
15
  中文 · [English](./README-en_US.md)
16
16
 
package/assets/menu.html CHANGED
@@ -195,7 +195,12 @@
195
195
  whistleBridge.copyText = options.copyText;
196
196
  whistleBridge.pageId = options.pageId;
197
197
  whistleBridge.compose = options.compose;
198
+ whistleBridge.composeInterrupt = options.createComposeInterrupt();
198
199
  whistleBridge.decodeBase64 = options.decodeBase64;
200
+ whistleBridge.joinBase64 = options.joinBase64;
201
+ whistleBridge.getReqId = options.getReqId;
202
+ whistleBridge.onComposeData = options.onComposeData;
203
+ whistleBridge.offComposeData = options.offComposeData;
199
204
  whistleBridge.importSessions = options.importSessions;
200
205
  whistleBridge.exportSessions = options.exportSessions;
201
206
  whistleBridge.importMockData = options.importMockData;
package/assets/modal.html CHANGED
@@ -18,7 +18,12 @@
18
18
  whistleBridge.copyText = options.copyText;
19
19
  whistleBridge.pageId = options.pageId;
20
20
  whistleBridge.compose = options.compose;
21
+ whistleBridge.composeInterrupt = options.createComposeInterrupt();
21
22
  whistleBridge.decodeBase64 = options.decodeBase64;
23
+ whistleBridge.joinBase64 = options.joinBase64;
24
+ whistleBridge.getReqId = options.getReqId;
25
+ whistleBridge.onComposeData = options.onComposeData;
26
+ whistleBridge.offComposeData = options.offComposeData;
22
27
  whistleBridge.importSessions = options.importSessions;
23
28
  whistleBridge.exportSessions = options.exportSessions;
24
29
  whistleBridge.importMockData = options.importMockData;
package/assets/tab.html CHANGED
@@ -288,7 +288,12 @@
288
288
  whistleBridge.copyText = options.copyText;
289
289
  whistleBridge.pageId = options.pageId;
290
290
  whistleBridge.compose = options.compose;
291
+ whistleBridge.composeInterrupt = options.createComposeInterrupt();
291
292
  whistleBridge.decodeBase64 = options.decodeBase64;
293
+ whistleBridge.joinBase64 = options.joinBase64;
294
+ whistleBridge.getReqId = options.getReqId;
295
+ whistleBridge.onComposeData = options.onComposeData;
296
+ whistleBridge.offComposeData = options.offComposeData;
292
297
  whistleBridge.importSessions = options.importSessions;
293
298
  whistleBridge.exportSessions = options.exportSessions;
294
299
  whistleBridge.importMockData = options.importMockData;
@@ -0,0 +1,50 @@
1
+ var LRU = require('lru-cache');
2
+
3
+ var cache = new LRU({ max: 100, maxAge: 1000 * 60 });
4
+ var MAX_SIZE = 1024 * 1280;
5
+
6
+ function getData(reqId) {
7
+ return cache.get(reqId);
8
+ }
9
+
10
+ exports = module.exports = function(req, res) {
11
+ var ids = req.query.ids;
12
+ var result = {};
13
+ ids = ids && typeof ids === 'string' ? ids.split(',') : ids;
14
+ if (!ids) {
15
+ return res.json(result);
16
+ }
17
+ ids.forEach(function(reqId) {
18
+ var curBuf = getData(reqId);
19
+ if (curBuf) {
20
+ if (curBuf._hasW2End) {
21
+ cache.del(reqId);
22
+ } else {
23
+ cache.set(reqId, '');
24
+ }
25
+ }
26
+ result[reqId] = curBuf ? curBuf.toString('base64') : curBuf;
27
+ });
28
+ res.json(result);
29
+ };
30
+
31
+ exports.setData = function(reqId, buffer, init) {
32
+ var curBuf = cache.get(reqId);
33
+ if (!init && curBuf == null) {
34
+ return false;
35
+ }
36
+ if (curBuf) {
37
+ if (buffer && curBuf.length < MAX_SIZE) {
38
+ cache.set(reqId, Buffer.concat([curBuf, buffer]));
39
+ }
40
+ } else {
41
+ cache.set(reqId, buffer || '');
42
+ }
43
+ return true;
44
+ };
45
+
46
+ exports.getData = getData;
47
+
48
+ exports.removeData = function(reqId) {
49
+ cache.del(reqId);
50
+ };
@@ -7,17 +7,17 @@ var extend = require('extend');
7
7
  var common = require('../../../lib/util/common');
8
8
  var config = require('../../../lib/config');
9
9
  var util = require('../../../lib/util');
10
- var zlib = require('../../../lib/util/zlib');
11
10
  var properties = require('../../../lib/rules/util').properties;
12
11
  var getSender = require('ws-parser').getSender;
13
12
  var hparser = require('hparser');
13
+ var composeData = require('./compose-data');
14
14
  var sendGzip = require('./util').sendGzip;
15
15
 
16
16
  var formatHeaders = hparser.formatHeaders;
17
17
  var getRawHeaders = hparser.getRawHeaders;
18
18
  var getRawHeaderNames = hparser.getRawHeaderNames;
19
19
  var parseReq = hparser.parse;
20
- var MAX_LENGTH = 1024 * 512;
20
+ var MAX_LENGTH = 1024 * 2048;
21
21
  var MAX_REQ_COUNT = 100;
22
22
  var TLS_PROTOS = 'https:,wss:,tls:'.split(',');
23
23
  var PROXY_OPTS = {
@@ -155,8 +155,7 @@ function handleWebSocket(options, cb, count) {
155
155
  }
156
156
  execCb && execCb(null, {
157
157
  statusCode: statusCode,
158
- headers: socket.headers || {},
159
- body: socket.body || ''
158
+ headers: socket.headers || {}
160
159
  });
161
160
  }, true);
162
161
  }
@@ -164,7 +163,7 @@ function handleWebSocket(options, cb, count) {
164
163
  }
165
164
  }
166
165
 
167
- function handleHttp(options, cb, count) {
166
+ function handleHttp(options, cb, count, reqId) {
168
167
  count = getReqCount(count);
169
168
  if (options.protocol === 'https:') {
170
169
  options.headers[config.HTTPS_FIELD] = 1;
@@ -182,42 +181,77 @@ function handleHttp(options, cb, count) {
182
181
  } else {
183
182
  options = extend({}, origOpts);
184
183
  }
185
- var client = http.request(options, function(res) {
186
- if (execCb) {
187
- res.on('error', execCb);
188
- var buffer;
189
- res.on('data', function(data) {
190
- if (buffer !== null) {
191
- buffer = buffer ? Buffer.concat([buffer, data]) : data;
192
- if (buffer.length > MAX_LENGTH) {
193
- buffer = null;
194
- }
184
+ var client = http.request(options, function(svrRes) {
185
+ if (!execCb) {
186
+ return drain(svrRes);
187
+ }
188
+ svrRes.on('error', execCb);
189
+ var buffer;
190
+ var enableStream;
191
+ var unzipStream = util.getUnzipStream(svrRes.headers);
192
+ var timer = reqId && setTimeout(function() {
193
+ composeData.setData(reqId, buffer, true);
194
+ enableStream = true;
195
+ timer = buffer = undefined;
196
+ handleResponse();
197
+ util.onResEnd(svrRes, function() {
198
+ var buf = composeData.getData(reqId);
199
+ if (buf) {
200
+ buf._hasW2End = true;
201
+ } else {
202
+ composeData.removeData(reqId);
195
203
  }
196
204
  });
197
- res.on('end', function() {
198
- zlib.unzip(res.headers['content-encoding'], buffer, function(err, body) {
199
- var headers = res.headers;
200
- if (typeof headers.trailer === 'string' && headers.trailer.indexOf(',') !== -1) {
201
- headers.trailer = headers.trailer.split(',');
202
- }
203
- var result = {
204
- statusCode: res.statusCode,
205
- headers: headers,
206
- trailers: res.trailers,
207
- rawHeaderNames: getRawHeaderNames(res.rawHeaders),
208
- rawTrailerNames: getRawHeaderNames(res.rawTrailers)
209
- };
210
- if (err) {
211
- result.body = err.stack;
212
- } else if (body) {
213
- result.base64 = body.toString('base64');
214
- }
215
- execCb(null, result);
216
- });
205
+ }, 3000);
206
+ var handleResponse = function() {
207
+ if (buffer === null) {
208
+ return;
209
+ }
210
+ timer && clearTimeout(timer);
211
+ var headers = svrRes.headers;
212
+ if (typeof headers.trailer === 'string' && headers.trailer.indexOf(',') !== -1) {
213
+ headers.trailer = headers.trailer.split(',');
214
+ }
215
+ var result = {
216
+ statusCode: svrRes.statusCode,
217
+ headers: headers,
218
+ trailers: svrRes.trailers,
219
+ rawHeaderNames: getRawHeaderNames(svrRes.rawHeaders),
220
+ rawTrailerNames: getRawHeaderNames(svrRes.rawTrailers),
221
+ reqId: timer ? undefined : reqId
222
+ };
223
+ result.base64 = buffer && buffer.toString('base64');
224
+ execCb(null, result);
225
+ buffer = null;
226
+ };
227
+ if (unzipStream) {
228
+ unzipStream.on('error', function(err) {
229
+ drain(svrRes);
230
+ execCb(err);
217
231
  });
232
+ svrRes.pipe(unzipStream);
218
233
  } else {
219
- drain(res);
234
+ unzipStream = svrRes;
220
235
  }
236
+ unzipStream.on('data', function(data) {
237
+ if (enableStream) {
238
+ if (!composeData.setData(reqId, data)) {
239
+ enableStream = false;
240
+ drain(svrRes);
241
+ svrRes.unpipe(unzipStream);
242
+ }
243
+ } else if (buffer !== null) {
244
+ buffer = buffer ? Buffer.concat([buffer, data]) : data;
245
+ if (buffer.length > MAX_LENGTH) {
246
+ handleResponse();
247
+ if (unzipStream !== svrRes) {
248
+ drain(svrRes);
249
+ svrRes.unpipe(unzipStream);
250
+ }
251
+ }
252
+ }
253
+ });
254
+ unzipStream.on('end', handleResponse);
221
255
  });
222
256
  client.on('error', execCb || util.noop);
223
257
  client.end(options.body);
@@ -356,7 +390,7 @@ module.exports = function(req, res) {
356
390
  } else if (isConn) {
357
391
  handleConnect(options, handleResponse, count);
358
392
  } else {
359
- handleHttp(options, handleResponse, count);
393
+ handleHttp(options, handleResponse, count, req.body.reqId);
360
394
  }
361
395
  if (!handleResponse) {
362
396
  res.json({ec: 0, em: 'success'});
@@ -8,6 +8,6 @@
8
8
  </head>
9
9
  <body style="overscroll-behavior-x: none;">
10
10
  <div id="container" class="main"></div>
11
- <script src="js/index.js?v=2.9.100"></script>
11
+ <script src="js/index.js?v=2.9.101"></script>
12
12
  </body>
13
13
  </html>