Skip to content

Commit

Permalink
⬆️ upgrading whistle
Browse files Browse the repository at this point in the history
  • Loading branch information
xcodebuild committed Jan 22, 2021
2 parents 35609b3 + cd0ee52 commit 1c043f7
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 70 deletions.
11 changes: 11 additions & 0 deletions vendor/whistle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# v2.6.3
1. style: 支持预览 SVG 文件
2. feat: 支持通过 `process.on('pforkError', (info) => {})` 获取插件抛出的异常信息
3. perf: 调整GC参数 `--max-semi-space-size=64`

# v2.6.2
1. fix: `v15.5.0` 版本界面无法打开问题

# v2.6.1
1. fix: `v15.5.0` 版本自动设置 `autoDestroy` 导致无法请求的问题

# v2.6.0
1. feat: 支持通过 `Online` 菜单查看当前进程的请求数、CPU、内存状态等
2. feat: 支持通过 `proxy.getRuntimeInfo()` 获取当前进程的请求数、CPU、内存状态等
Expand Down
2 changes: 1 addition & 1 deletion vendor/whistle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Manipulations to http request and response in whistle can be achieved as a **Rul

Description:

1. **pattern** is an expression to match the target request url. You can write patterns in different forms including domain, path, reqular expression, wildcard, and so on.
1. **pattern** is an expression to match the target request url. You can write patterns in different forms including domain, path, regular expression, wildcard, and so on.

# matching domain
www.example.com
Expand Down
2 changes: 1 addition & 1 deletion vendor/whistle/biz/webui/htdocs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@
</head>
<body>
<div id="container" class="main"></div>
<script src="js/index.js?v=2.6.0"></script>
<script src="js/index.js?v=2.6.3"></script>
</body>
</html>
12 changes: 6 additions & 6 deletions vendor/whistle/biz/webui/htdocs/js/index.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions vendor/whistle/biz/webui/htdocs/src/js/res-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ var ResDetail = React.createClass({
headersStr = ['HTTP/' + (modal.req.httpVersion || '1.1'), status, util.getStatusMessage(res)].join(' ')
+ '\r\n' + headersStr;
raw = headersStr + '\r\n\r\n' + body;
var type = util.getContentType(headers);
var rawType = util.getRawType(headers);
var type = util.getContentType(rawType);
isJson = type === 'JSON';
if (type === 'IMG') {
// 对 SVG 做特殊处理, 利用 base64 ,图片标签展示 svg 元素
if (rawType === 'image/svg+xml') {
imgSrc = 'data:image/svg+xml;base64,' + (res.base64 || '');
isText = false;
} else if (type === 'IMG') {
imgSrc = body || (res.size ? modal.url : undefined);
isText = false;
} else if (showImg && res.base64 && type === 'HTML') {
Expand Down
2 changes: 2 additions & 0 deletions vendor/whistle/biz/webui/htdocs/src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ function getRawType(type) {
return typeof type === 'string' ? type.split(';')[0].trim().toLowerCase() : '';
}

exports.getRawType = getRawType;

exports.getExtension = function(headers) {
var suffix = getContentType(headers);
var type;
Expand Down
12 changes: 6 additions & 6 deletions vendor/whistle/biz/webui/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ app.use(function(req, res, next) {
res.destroy();
}
};
req.on('error', abort).on('close', abort);
res.on('error', abort);
req.on('error', abort);
res.on('error', abort).on('close', abort);
next();
});

Expand Down Expand Up @@ -179,11 +179,11 @@ app.use(function(req, res, next) {
});

function cgiHandler(req, res) {
if (req.headers.origin) {
res.setHeader('access-control-allow-origin', req.headers.origin);
res.setHeader('access-control-allow-credentials', true);
}
try {
if (req.headers.origin) {
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader('Access-Control-Allow-Credentials', true);
}
require(path.join(__dirname, '..' + req.path))(req, res);
} catch(err) {
res.status(500).send(config.debugMode ?
Expand Down
4 changes: 2 additions & 2 deletions vendor/whistle/docs/zh/rules/@.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @
这是一个特殊的符合,主要有一些功能:
这是一个特殊的符号,主要有一些功能:

1. 作为附加值带给插件或[reqScript.html](reqScript.html)[resScript.html](resScript.html)
```
Expand All @@ -18,4 +18,4 @@
@~/xxx/test.txt
```
> 本地路径必须为绝对路径,如:`/User/xxx/test.txt``~/xxx/test.txt``e:/xxx/test.txt``e:\xxx\test.txt`,其中本地路径分割`/``\` 等价
4. 功能扩展,具体参见:[nohost](https://github.com/imweb/nohost)
4. 功能扩展,具体参见:[nohost](https://github.com/imweb/nohost)
2 changes: 1 addition & 1 deletion vendor/whistle/lib/https/h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function getClient(req, socket, name) {
}

function requestH2(client, req, res, callback) {
if (req.hasError) {
if (req._hasError) {
return;
}
var headers = util.formatH2Headers(req.headers);
Expand Down
2 changes: 0 additions & 2 deletions vendor/whistle/lib/https/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,6 @@ function addClientInfo(socket, chunk, statusLine, clientIp, clientPort) {

module.exports = function(socket, next, isWebPort) {
var reqSocket, reqDestroyed, resDestroyed;
var tunnelHost = socket.tunnelHost;
var headersStr, statusLine;
function destroy(err) {
if (reqSocket) {
Expand Down Expand Up @@ -948,7 +947,6 @@ module.exports = function(socket, next, isWebPort) {
tunnelTmplData.set(reqSocket.localPort + ':' + reqSocket.remotePort, {
clientIp: clientIp,
clientPort: clientPort,
tunnelHost: tunnelHost,
clientId: headers[config.CLIENT_ID_HEADER],
proxyAuth:headers['proxy-authorization'],
tunnelData: headers[config.TUNNEL_DATA_HEADER]
Expand Down
21 changes: 13 additions & 8 deletions vendor/whistle/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@ var config = require('./config');
var HTTPS_RE = /^https:/i;

function addErrorEvents(req, res) {
var countdown = function() {
if (req.isLogRequests) {
req.isLogRequests = false;
--util.httpRequests;
}
};
var clientReq;
req.on('dest', function(_req) {
clientReq = _req;
if (!req.noReqBody) {
clientReq.on('error', abort);
}
}).on('error', abort).once('close', abort);
}).on('error', abort);
res.on('src', function(_res) {
if (clientReq && req.noReqBody) {
clientReq.on('error', abort);
}
_res.on('error', abort);
}).on('error', abort);
}).on('error', abort)
.once('close', abort)
.once('finish', countdown);

function abort(err) {
if (clientReq === false) {
return;
}
if (req.isLogRequests) {
req.isLogRequests = false;
--util.httpRequests;
}
req.hasError = true;
clientReq = clientReq || req._clientReq;
countdown();
req._hasError = true;
clientReq = req._clientReq || clientReq;
if (clientReq) {
if (clientReq.abort) {
clientReq.abort();
Expand Down
4 changes: 2 additions & 2 deletions vendor/whistle/lib/inspectors/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ function emitDataEvents(req, res, proxy) {
}
!hasResPipe && handleResBody(res, _res);
});
req.once('close', handleError);
req.once('error', handleError);
res.once('error', handleError);
res.once('close', handleError);

function handleError(err) {
req.hasError = true;
req._hasError = true;
if ((!err || !err._resError) && (data.endTime || (data.responseTime && !err))) {//connection: close的时候,还要数据缓存
return;
}
Expand Down
18 changes: 11 additions & 7 deletions vendor/whistle/lib/inspectors/res.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ function notAllowCache(resRules) {
}

function pipeClient(req, client) {
if (req.hasError) {
if (req._hasError) {
client.abort();
} else if (req.noReqBody) {
req._clientReq = client;
client.end();
util.drain(req, function() {
if (!req._hasError) {
client.end();
}
});
} else {
req.pipe(client);
}
Expand Down Expand Up @@ -369,7 +372,7 @@ module.exports = function(req, res, next) {
curClient.on('error', util.noop);
curClient = null;
}
if (req.hasError || req._hasRespond) {
if (req._hasError || req._hasRespond) {
return;
}
if (err && isHttps && !options.ciphers && util.isCiphersError(err)) {
Expand Down Expand Up @@ -458,7 +461,7 @@ module.exports = function(req, res, next) {
send();
};
var send = function(sock) {
if (req.hasError) {
if (req._hasError) {
return;
}
req.useH2 = false;
Expand All @@ -481,6 +484,7 @@ module.exports = function(req, res, next) {
try {
var client = (isHttps ? https : http).request(options, res.response);
curClient = client;
req._clientReq = client;
client.once('error', retry);
client.once('close', retry);
client.once('socket', function(socket) {
Expand Down Expand Up @@ -556,7 +560,7 @@ module.exports = function(req, res, next) {
optHeaders[config.PLUGIN_HOOK_NAME_HEADER] = config.PLUGIN_HOOKS.HTTP;
}
req.noReqBody = !util.hasRequestBody(req);
if (req.hasError) {
if (req._hasError) {
return;
}
if (req.method === 'DELETE' && (req._hasInjectBody ||
Expand Down Expand Up @@ -978,7 +982,7 @@ module.exports = function(req, res, next) {
}

notAllowCache(resRules) && util.disableReqCache(req.headers);
if (!req.hasError) {
if (!req._hasError) {
next();
}
};
27 changes: 7 additions & 20 deletions vendor/whistle/lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,22 +802,19 @@ function getPipe(type, hookName) {
}
var options = getOptions(req, res, isRes && 'resRules');
options.headers[PLUGIN_HOOK_NAME_HEADER] = hookName;
var done, hasError, pipeSock;
var pipeSock;
options.proxyHost = LOCALHOST;
options.proxyPort = port;
delete options.headers[CUSTOM_PARSER_HEADER];
var handleError = function(err) {
if (!hasError && !done) {
hasError = done = true;
err && config.debugMode && console.log(req._pipeRule.matcher, type, err);
err = err || new Error('closed');
pipeSock && pipeSock.destroy();
(res || req).emit('error', err);
}
err && config.debugMode && console.log(req._pipeRule.matcher, type, err);
err = err || new Error('closed');
pipeSock && pipeSock.destroy();
(res || req).emit('error', err);
};
var handleConnect = function(socket, _res) {
util.onSocketEnd(socket, handleError);
if (done) {
if (req._hasError) {
return socket.destroy();
}
pipeSock = socket;
Expand All @@ -832,19 +829,9 @@ function getPipe(type, hookName) {
}
var client = config.connect(options, handleConnect);
client.on('error', function() {
client = !done && config.connect(options, handleConnect);
client = !req._hasError && config.connect(options, handleConnect);
client && util.onSocketEnd(client, handleError);
});
var handleClose = function() {
done = true;
client && req._hasError && client.abort();
};
if (res) {
res.on('finish', handleClose);
} else {
req.on('end', handleClose);
}
util.onSocketEnd(req, handleClose);
});
};
}
Expand Down
3 changes: 3 additions & 0 deletions vendor/whistle/lib/rules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,9 @@ proto.resolveHost = function(req, callback, pluginRulesMgr, rulesFileMgr, header
if (host) {
return callback(null, util.removeProtocol(host.matcher, true), host.port, host);
}
if (req.rules) {
delete req.rules.host;
}
this.lookupHost(req, callback);
};

Expand Down
1 change: 0 additions & 1 deletion vendor/whistle/lib/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ function tunnelProxy(server, proxy) {
}
if (!reqSocket._hasError && isIntercept()) {
reqSocket.rulesHeaders = req.rulesHeaders;
reqSocket.tunnelHost = options.host;
reqSocket.enable = req.enable;
reqSocket.disable = req.disable;
reqSocket._curHostname = hostname;
Expand Down
6 changes: 5 additions & 1 deletion vendor/whistle/lib/util/drain.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ var PassThrough = require('stream').PassThrough;
var noop = function() {};

module.exports = function(stream, endHandler) {
if (stream._hasAlreadyDrain) {
return typeof endHandler == 'function' && endHandler();
}
stream._hasAlreadyDrain = true;
var emitEndStream = new PassThrough();
emitEndStream.on('data', noop).on('error', noop);
typeof endHandler == 'function' && emitEndStream.on('end', endHandler);
emitEndStream.on('end', endHandler);
stream.pipe(emitEndStream);
};
5 changes: 5 additions & 0 deletions vendor/whistle/lib/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,11 @@ function transformReq(req, res, port, host, useProxy) {
}
options.hostname = null;
var client = http.request(options, function(_res) {
var origin = !_res.headers['access-control-allow-origin'] && req.headers.origin;
if (origin) {
_res.headers['access-control-allow-origin'] = origin;
_res.headers['access-control-allow-credentials'] = true;
}
if (getStatusCode(_res.statusCode)) {
res.writeHead(_res.statusCode, _res.headers);
_res.pipe(res);
Expand Down
14 changes: 7 additions & 7 deletions vendor/whistle/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/whistle/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "whistle",
"description": "HTTP, HTTP2, HTTPS, Websocket debugging proxy",
"version": "2.6.0",
"version": "2.6.3",
"dataDirname": ".whistle",
"localUIHost": "local.whistlejs.com",
"port": 8899,
Expand Down Expand Up @@ -53,13 +53,13 @@
"node-native-zip2": "^1.0.0",
"node-pac": "^0.4.0",
"parseurl": "^1.3.1",
"pfork": "^0.3.6",
"pfork": "^0.5.2",
"pipestream": "^0.7.1",
"q": "1.4.1",
"safe-buffer": "^5.1.2",
"sni": "1.0.0",
"sockx": "^0.2.0",
"starting": "^6.2.1",
"starting": "^7.0.1",
"weinre2": "^1.3.0",
"ws-parser": "^0.6.0",
"xml2js": "0.4.17"
Expand Down

0 comments on commit 1c043f7

Please sign in to comment.