Skip to content

Commit

Permalink
refactor: refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
avwo committed Jun 11, 2020
1 parent e2269b0 commit 53ada81
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/inspectors/res.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ module.exports = function(req, res, next) {
var isHtml = type === 'HTML';
var isJs = isHtml || type === 'JS';
var isCss = isHtml || type === 'CSS';
var hasResBody = util.hasBody(_res, req);
util.getRuleValue([resRules.resBody, resRules.resPrepend, resRules.resAppend,
isHtml && resRules.htmlAppend, isJs && resRules.jsAppend, isCss && resRules.cssAppend,
isHtml && resRules.htmlBody, isJs && resRules.jsBody, isCss && resRules.cssBody,
Expand Down Expand Up @@ -801,7 +802,7 @@ module.exports = function(req, res, next) {
extend(headers, cusHeaders);
}

if (!util.hasBody(_res, req)) {
if (!hasResBody) {
delete data.speed;
delete data.body;
delete data.top;
Expand All @@ -817,15 +818,15 @@ module.exports = function(req, res, next) {
}
res.addZipTransform(new WhistleTransform(data));
}
if (util.hasBody(_res, req)) {
if (hasResBody) {
handleReplace(res, replacement);
}
//一定放在最后,确保能过滤到动态注入的内容
if (speedTransform) {
res.add(speedTransform);
}

var bodyFile = util.hasBody(_res, req) ? getWriterFile(util.getRuleFile(resRules.resWrite), _res.statusCode) : null;
var bodyFile = hasResBody ? getWriterFile(util.getRuleFile(resRules.resWrite), _res.statusCode) : null;
var rawFile = getWriterFile(util.getRuleFile(resRules.resWriteRaw), _res.statusCode);
util.getFileWriters([bodyFile, rawFile], function(writer, rawWriter) {
res.on('src', function(_res) {
Expand Down Expand Up @@ -865,7 +866,7 @@ module.exports = function(req, res, next) {
util.emitError(res, e);
}
});
}, !util.hasBody(_res, req), charset, isHtml);
}, !hasResBody, charset, isHtml);
});
});
});
Expand Down

0 comments on commit 53ada81

Please sign in to comment.