whistle 2.9.108 → 2.10.0

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.
Files changed (40) hide show
  1. package/bin/util.js +1 -1
  2. package/biz/index.js +12 -10
  3. package/biz/webui/cgi-bin/certs/active.js +6 -0
  4. package/biz/webui/cgi-bin/certs/remove.js +0 -1
  5. package/biz/webui/cgi-bin/certs/upload.js +0 -1
  6. package/biz/webui/cgi-bin/util.js +7 -20
  7. package/biz/webui/htdocs/index.html +1 -1
  8. package/biz/webui/htdocs/js/index.js +41 -41
  9. package/biz/webui/lib/index.js +10 -13
  10. package/lib/config.js +17 -36
  11. package/lib/handlers/file-proxy.js +2 -1
  12. package/lib/handlers/http-proxy.js +1 -1
  13. package/lib/https/ca.js +34 -27
  14. package/lib/https/h2.js +1 -1
  15. package/lib/https/index.js +21 -17
  16. package/lib/index.js +1 -1
  17. package/lib/init.js +13 -12
  18. package/lib/inspectors/req.js +13 -10
  19. package/lib/inspectors/res.js +375 -390
  20. package/lib/inspectors/rules.js +11 -0
  21. package/lib/plugins/compat.js +108 -0
  22. package/lib/plugins/get-plugins-sync.js +1 -4
  23. package/lib/plugins/index.js +92 -284
  24. package/lib/plugins/load-plugin.js +205 -223
  25. package/lib/plugins/module-paths.js +3 -4
  26. package/lib/plugins/proxy.js +4 -7
  27. package/lib/rules/index.js +69 -66
  28. package/lib/rules/protocols.js +6 -0
  29. package/lib/rules/rules.js +43 -31
  30. package/lib/rules/util.js +30 -0
  31. package/lib/service/composer.js +5 -5
  32. package/lib/service/util.js +7 -21
  33. package/lib/tunnel.js +15 -12
  34. package/lib/upgrade.js +8 -9
  35. package/lib/util/common.js +171 -48
  36. package/lib/util/file-mgr.js +3 -7
  37. package/lib/util/index.js +101 -143
  38. package/package.json +1 -1
  39. package/README-en_US.md +0 -80
  40. package/biz/webui/htdocs/img/assistant.svg +0 -1
package/bin/util.js CHANGED
@@ -121,7 +121,7 @@ function showUsage(isRunning, options, restart) {
121
121
  exports.showUsage = showUsage;
122
122
 
123
123
  function getDataDir() {
124
- return path.resolve(config.getHomedir(), '.startingAppData');
124
+ return path.resolve(common.getHomedir(), '.startingAppData');
125
125
  }
126
126
 
127
127
  function formatOptions(options) {
package/biz/index.js CHANGED
@@ -4,6 +4,7 @@ var util = require('../lib/util');
4
4
  var handleUIReq = require('./webui/lib').handleRequest;
5
5
  var handleWeinreReq = require('./weinre');
6
6
  var config = require('../lib/config');
7
+ var common = require('../lib/util/common');
7
8
 
8
9
  var localIpCache = util.localIpCache;
9
10
  var WEBUI_PATH = config.WEBUI_PATH;
@@ -31,7 +32,8 @@ module.exports = function(req, res, next) {
31
32
  var config = this.config;
32
33
  var pluginMgr = this.pluginMgr;
33
34
  var fullUrl = req.fullUrl = util.getFullUrl(req); // format request
34
- var host = util.parseHost(req.headers.host);
35
+ var headers = req.headers;
36
+ var host = util.parseHost(headers.host);
35
37
  var port = host[1] || (req.isHttps ? 443 : 80);
36
38
  var bypass;
37
39
  host = host[0];
@@ -59,12 +61,12 @@ module.exports = function(req, res, next) {
59
61
  var realPath = RegExp.$1;
60
62
  var realPort = RegExp.$3;
61
63
  realHost = RegExp.$2 + (realPort ? ':' + realPort : '');
62
- req.headers[config.REAL_HOST_HEADER] = realHost;
64
+ headers[util.REAL_HOST_HEADER] = realHost;
63
65
  req.url = req.url.replace(realPath, '');
64
66
  } else {
65
67
  req.curUrl = fullUrl;
66
68
  if (realHost = rules.resolveInternalHost(req)) {
67
- req.headers[config.REAL_HOST_HEADER] = realHost;
69
+ headers[util.REAL_HOST_HEADER] = realHost;
68
70
  }
69
71
  }
70
72
  if (internalAppRe.test(req.path)) {
@@ -79,7 +81,7 @@ module.exports = function(req, res, next) {
79
81
  isProxyReq = isProxyReq || isOld;
80
82
  } else if (pluginRe.test(req.path)) {
81
83
  isProxyReq = !pluginMgr.getPlugin(RegExp.$1 + ':');
82
- } else if (!req.headers[config.WEBUI_HEAD]) {
84
+ } else if (!headers[config.WEBUI_HEAD]) {
83
85
  isWebUI = false;
84
86
  }
85
87
  if (!config.proxyServer && isProxyReq && !config.isLocalUIUrl(host)) {
@@ -90,11 +92,11 @@ module.exports = function(req, res, next) {
90
92
  if (isWebUI) {
91
93
  req.fromInternalPath = true;
92
94
  var hostname = (req._fwdHost && util.parseHost(req._fwdHost)[0]) || host;
93
- req.headers['x-whistle-origin-host'] = hostname || '*';
95
+ headers[common.ORIGIN_HOST_HEADER] = hostname || '*';
94
96
  }
95
97
  }
96
98
  } else {
97
- isWebUI = req.headers[config.WEBUI_HEAD];
99
+ isWebUI = headers[config.WEBUI_HEAD];
98
100
  if (!isWebUI) {
99
101
  if (!(isWebUI = localIpCache.get(host))) {
100
102
  isWebUI = config.isLocalUIUrl(host);
@@ -106,7 +108,7 @@ module.exports = function(req, res, next) {
106
108
  localIpCache.set(host, 1);
107
109
  }
108
110
  if (PREVIEW_PATH_RE.test(req.url)) {
109
- req.headers[config.INTERNAL_ID_HEADER] = config.INTERNAL_ID;
111
+ headers[util.INTERNAL_ID_HEADER] = util.INTERNAL_ID;
110
112
  req.url = '/preview.html?charset=' + RegExp.$1;
111
113
  isWebUI = true;
112
114
  } else if (isWebUI) {
@@ -118,7 +120,7 @@ module.exports = function(req, res, next) {
118
120
  if (bypass) {
119
121
  req.url = req.url.replace(bypass, '/');
120
122
  }
121
- delete req.headers[config.INTERNAL_ID_HEADER];
123
+ delete headers[util.INTERNAL_ID_HEADER];
122
124
  }
123
125
  }
124
126
  // 后续有用到
@@ -137,7 +139,7 @@ module.exports = function(req, res, next) {
137
139
  var outerPort = RegExp.$2;
138
140
  req.url = req.url.replace(RegExp['$&'], '/' + RegExp.$1 + '/');
139
141
  if (outerPort > 0 && outerPort < 65536 && outerPort != config.port) {
140
- req.headers.host = '127.0.0.1:' + outerPort;
142
+ headers.host = '127.0.0.1:' + outerPort;
141
143
  return util.transformReq(req, res, outerPort);
142
144
  }
143
145
  }
@@ -151,7 +153,7 @@ module.exports = function(req, res, next) {
151
153
  } else if (localRule = rules.resolveLocalRule(req)) {
152
154
  req.url = localRule.url;
153
155
  if (localRule.realPort) {
154
- req.headers.host = '127.0.0.1:' + localRule.realPort;
156
+ headers.host = '127.0.0.1:' + localRule.realPort;
155
157
  util.transformReq(req, res, localRule.realPort);
156
158
  } else {
157
159
  transformUI(req, res);
@@ -0,0 +1,6 @@
1
+ var ca = require('../../../../lib/https/ca');
2
+
3
+ module.exports = function(req, res) {
4
+ ca.setActiveCert(req.body);
5
+ res.json(ca.getCustomCertsFiles());
6
+ };
@@ -1,6 +1,5 @@
1
1
  var ca = require('../../../../lib/https/ca');
2
2
 
3
-
4
3
  module.exports = function(req, res) {
5
4
  ca.removeCert(req.body);
6
5
  var isparsed = req.query.dataType === 'parsed';
@@ -1,6 +1,5 @@
1
1
  var ca = require('../../../../lib/https/ca');
2
2
 
3
-
4
3
  module.exports = function(req, res) {
5
4
  ca.uploadCerts(req.body);
6
5
  var isparsed = req.query.dataType === 'parsed';
@@ -2,6 +2,7 @@ var util = require('../../../lib/util');
2
2
  var config = require('../../../lib/config');
3
3
  var proc = require('../../../lib/util/process');
4
4
  var rulesUtil = require('../../../lib/rules/util');
5
+ var padLeft = require('../../../lib/util/common').padLeft;
5
6
 
6
7
  var properties = rulesUtil.properties;
7
8
  var rules = rulesUtil.rules;
@@ -118,30 +119,16 @@ exports.getReqData = function(req, callback) {
118
119
  });
119
120
  };
120
121
 
121
- function padding(num) {
122
- return num < 10 ? '0' + num : num;
123
- }
124
-
125
- function paddingMS(ms) {
126
- if (ms > 99) {
127
- return ms;
128
- }
129
- if (ms > 9) {
130
- return '0' + ms;
131
- }
132
- return '00' + ms;
133
- }
134
-
135
122
  function formatDate() {
136
123
  var date = new Date();
137
124
  var result = [];
138
125
  result.push(date.getFullYear());
139
- result.push(padding(date.getMonth() + 1));
140
- result.push(padding(date.getDate()));
141
- result.push(padding(date.getHours()));
142
- result.push(padding(date.getMinutes()));
143
- result.push(padding(date.getSeconds()));
144
- result.push(paddingMS(date.getMilliseconds()));
126
+ result.push(padLeft(date.getMonth() + 1));
127
+ result.push(padLeft(date.getDate()));
128
+ result.push(padLeft(date.getHours()));
129
+ result.push(padLeft(date.getMinutes()));
130
+ result.push(padLeft(date.getSeconds()));
131
+ result.push(padLeft(date.getMilliseconds(), 3));
145
132
  return result.join('');
146
133
  }
147
134
 
@@ -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.108"></script>
11
+ <script src="js/index.js?v=2.10.0"></script>
12
12
  </body>
13
13
  </html>