Skip to content

Commit 259900a

Browse files
committed
Squashed 'vendor/whistle/' changes from 826e040c9..d70edcf1a
d70edcf1a refactor: refine filter ff9057d89 Release v2.7.11 4199c35e1 feat: self <=> clientIp + clientId 94806503c Release v2.7.11 00f9e498f feat: add composer client id 084e85238 Release v2.7.11 97141bf73 refactor: refine code 78dfff7da feat: add async await 66edff85e feat: send rule value to pipe server 404c1850b refactor: refine code a6359c0c2 refactor: refine fullUrl 9ab9a344e style: refine tips 5f69ac741 feat: export baseUrl to plugin 4828aa739 Release v2.7.10 11e5a5ba1 refactor: onPluginLoad -> pluginLoad b8a7a3615 Merge branch 'v2.x' 3257eb7a3 docs: https cd74f1d0c refactor: info -> data 06d1d379e refactor: refine plugin hooks 0e3b788e3 Release v2.7.10 1a9a1c3e9 feat: add proxy.on('perfChange') 05f384348 docs: mode-options.md 7d3a56225 Release v2.7.10 c46db1549 feat: add -M disableForwardedHost|disableForwardedProto 1eeb44d0a style: Raw Url -> Original Url b94220350 refactor: refine code ab0332b73 docs: update linux docs 2d20fd519 feat(zh/https.md): 添加 Linux 添加根证书的方法 d809d8530 refactor: update iconv-lite 7cf23836e Release v2.7.9 b39ca4ed5 feat: add /cgi-bin/top f1c5b4367 feat: add onPluginLoadError onPluginLoad events 45893fb77 refactor: refine code e5b2cdbd3 refactor: refine code a4e578e05 feat: emit plugin events d2d472aa4 feat: add tpl var whistle.xxx.[g][all]var af1693c06 Release v2.7.9 ec7e79196 refactor: refine code 01890e59f test: pluginVars e1b2741cf refactor: refine code fd496b19e refactor: pluginVar -> pluginVars 77ad47138 refactor: pluginVars -> globalPluginVars 3e0a965da refactor: refine code 125a2ecc4 feat: add pluginVar 23bd9f54f fix:remove ADD command, using ENTRYPOINT 2bdb5ec29 refactor: refine code f8aa063f4 Release v2.7.8 bcf3145ee Release v2.7.8 cb2f5b7ed refactor: refine code 40d792214 feat: add Dockerfile f4572a340 Create Dockerfile cafa8f47f refactor: res.flushHeaders ccfffa798 refactor: automatically load all plug-ins in the upper directory of the plug-in in debug mode 8daf8f97c style: refine code 534c16659 refactor: cors ignores requests without origin git-subtree-dir: vendor/whistle git-subtree-split: d70edcf1ae915a27af8fd2ada280b4fa4a886430
1 parent fe807f2 commit 259900a

38 files changed

+10185
-861
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ assets/launcher
6363
/docs
6464
/.history
6565
CHANGELOG.md
66+
Dockerfile
6667

6768

6869
# Coveralls

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
2+
# v2.7.11
3+
1. feat: 插件 hook 支持 `async-await`
4+
5+
``` js
6+
module.exports = async (server, options) => {
7+
// ... do sth
8+
};
9+
```
10+
2. feat: `pipe://xxx` 支持插件内部通过 `req.originalReq.ruleValue` 获取 `xxx://value``value`
11+
12+
# v2.7.10
13+
1. feat: 支持通过 `-M disableForwardedHost` 禁止 Whistle 使用 `x-forwarded-host` 请求头,默认 Whistle 会用该请求头作为请求 URL 的域名
14+
2. feat: 支持通过 `-M disableForwardedProto` 禁止 Whistle 使用 `x-forwarded-proto` 请求头,默认当该请求头值为 `https` 时, Whistle 会把请求当成 HTTPS 处理
15+
3. feat: 第三方通过 `const proxy = startWhistle(options);` 启动 Whistle 时,可以通过 `proxy.on('perfDataChange', (perfData) => {})` 获取 cpu、内存、请求量等数据
16+
4. refactor: 第三方通过 `const proxy = startWhistle(options);` 启动 Whistle 时,可以通过 `proxy.on('pluginLoad', child, name, moduleName);``proxy.on('pluginLoadError', err, name, moduleName);` 监听插件启动信息
17+
18+
# v2.7.9
19+
1. feat: 支持 `pattern %plugin=xxx`
20+
2. feat: 支持插件通过 `options.getTop(data => data && console.log(data))` 获取所在 Whistle 的 CPU、内存及请求量等信息
21+
22+
# v2.7.8
23+
1. feat: 源码目录添加 Dockerfile: https://github.com/avwo/whistle/pull/601
24+
2. feat: 支持在插件的根目录执行 `w2 run` 时自动加载该插件
25+
3. refactor: 设置 `resCors://enable` 如果请求头不存在 `origin` 则自动忽略该设置
26+
4. fix: https://github.com/avwo/whistle/issues/600
27+
128
# v2.7.7
229
1. fix: [pipe](https://wproxy.org/whistle/rules/pipe.html) 无法直接透传 WebSocket 的二进制包问题
330
2. style: 支持显示自定义根证书及删除自定义证书导引

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine
2+
EXPOSE 8899
3+
RUN apk add --no-cache nodejs npm \
4+
&& npm install whistle -g \
5+
&& apk del npm \
6+
&& mkdir /whistle
7+
ENTRYPOINT ["w2", "run", "-M","prod", "-D","/whistle"]

biz/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ module.exports = function(req, res, next) {
5050
var realPath = RegExp.$1;
5151
var realPort = RegExp.$3;
5252
realHost = RegExp.$2 + (realPort ? ':' + realPort : '');
53-
req.headers['x-whistle-real-host'] = realHost;
53+
req.headers[config.REAL_HOST_HEADER] = realHost;
5454
req.url = req.url.replace(realPath, '');
5555
fullUrl = util.getFullUrl(req);
5656
} else {
5757
req.curUrl = fullUrl;
5858
if (realHost = rules.resolveInternalHost(req)) {
59-
req.headers['x-whistle-real-host'] = realHost;
59+
req.headers[config.REAL_HOST_HEADER] = realHost;
6060
fullUrl = util.getFullUrl(req);
6161
}
6262
}

biz/webui/cgi-bin/composer.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ var PROXY_OPTS = {
2020
port: config.port
2121
};
2222

23-
function parseHeaders(headers, rawHeaderNames) {
23+
function parseHeaders(headers, rawHeaderNames, clientId) {
2424
if (!headers || typeof headers != 'string') {
2525
return {};
2626
}
2727

2828
var reqHeaders = util.parseRawJson(headers);
2929
if (reqHeaders) {
30-
return util.lowerCaseify(reqHeaders, rawHeaderNames);
30+
reqHeaders = util.lowerCaseify(reqHeaders, rawHeaderNames);
31+
} else {
32+
reqHeaders = util.parseHeaders(headers, rawHeaderNames);
3133
}
32-
33-
return util.parseHeaders(headers, rawHeaderNames);
34+
if (clientId && reqHeaders[config.CLIENT_ID_HEADER] !== clientId) {
35+
reqHeaders[config.COMPOSER_CLIENT_ID_HEADER] = clientId;
36+
}
37+
return reqHeaders;
3438
}
3539

3640
function isWebSocket(options) {
@@ -105,7 +109,7 @@ function handleWebSocket(options, cb) {
105109
var body = '';
106110
if (index !== -1) {
107111
socket.removeListener('data', handleResponse);
108-
socket.headers = parseHeaders(resData.slice(0, index) + '');
112+
socket.headers = parseHeaders(resData.slice(0, index) + '', null, options.clientId);
109113
body = resData.slice(index + 4);
110114
var sender = getSender(socket);
111115
var data = options.body;
@@ -218,10 +222,12 @@ module.exports = function(req, res) {
218222
options.protocol = protocol = protocol.toLowerCase();
219223
}
220224
var rawHeaderNames = {};
221-
var headers = parseHeaders(req.body.headers, rawHeaderNames);
225+
var clientId = req.headers[config.CLIENT_ID_HEADER];
226+
var headers = parseHeaders(req.body.headers, rawHeaderNames, clientId);
222227
delete headers[config.WEBUI_HEAD];
223228
headers[config.WHISTLE_REQ_FROM_HEADER] = 'W2COMPOSER';
224229
headers.host = options.host;
230+
options.clientId = clientId;
225231
var clientIp = util.getClientIp(req);
226232
if (!util.isLocalAddress(clientIp)) {
227233
headers[config.CLIENT_IP_HEAD] = clientIp;

biz/webui/cgi-bin/top.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var proc = require('../../../lib/util/process');
2+
3+
module.exports = function(req, res) {
4+
res.json(proc);
5+
};

biz/webui/htdocs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
</head>
99
<body>
1010
<div id="container" class="main"></div>
11-
<script src="js/index.js?v=2.7.7"></script>
11+
<script src="js/index.js?v=2.7.11"></script>
1212
</body>
1313
</html>

biz/webui/htdocs/js/index.js

Lines changed: 25 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

biz/webui/htdocs/src/js/data-center.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ function startLoadData() {
599599
inited = true;
600600
$.extend(options, hashFilterObj);
601601
if (onlyViewOwnData) {
602-
options.ip = 'self,clientId';
602+
options.ip = 'self';
603603
}
604604
cgi.getData(options, function (data) {
605605
var hasNewData = data && data.data && data.data.hasNew;

biz/webui/htdocs/src/js/files-dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ var FilesDialog = React.createClass({
180180
},
181181
remove: function(e) {
182182
var name = e.target.getAttribute('data-name');
183-
if (!confirm('Are you sure to delete this file \'' + name + '\'.')) {
183+
if (!confirm('Are you sure to delete \'' + name + '\'.')) {
184184
return;
185185
}
186186
var self = this;

0 commit comments

Comments
 (0)