diff --git a/packages/mitmproxy/src/options.js b/packages/mitmproxy/src/options.js index 5ed6c40..f7db3c8 100644 --- a/packages/mitmproxy/src/options.js +++ b/packages/mitmproxy/src/options.js @@ -124,12 +124,9 @@ module.exports = (serverConfig) => { const matchInterceptsOpts = {} for (const regexp in interceptOpts) { // 遍历拦截配置 // 判断是否匹配拦截器 - let matched - if (regexp !== true && regexp !== 'true') { - matched = matchUtil.isMatched(rOptions.path, regexp) - if (matched == null) { // 拦截器匹配失败 - continue - } + const matched = matchUtil.isMatched(rOptions.path, regexp) + if (matched == null) { // 拦截器匹配失败 + continue } // 获取拦截器 diff --git a/packages/mitmproxy/src/utils/util.match.old.js b/packages/mitmproxy/src/utils/util.match.old.js deleted file mode 100644 index ff2b1fc..0000000 --- a/packages/mitmproxy/src/utils/util.match.old.js +++ /dev/null @@ -1,53 +0,0 @@ -// 警告:此文件不再使用,仅用于测试,可在 test/matchUtilTest.js 中比对新逻辑与旧逻辑的效果差异 - -const lodash = require('lodash') -function isMatched (url, regexp) { - return url.match(regexp) -} - -function domainRegexply (target) { - return target.replace(/\./g, '\\.').replace(/\*/g, '.*') -} - -function domainMapRegexply (hostMap) { - const regexpMap = {} - if (hostMap == null) { - return regexpMap - } - lodash.each(hostMap, (value, domain) => { - if (domain.indexOf('*') >= 0) { - const regDomain = domainRegexply(domain) - regexpMap[regDomain] = value - } else { - regexpMap[domain] = value - } - }) - return regexpMap -} - -function matchHostname (hostMap, hostname) { - if (hostMap == null) { - return null - } - const value = hostMap[hostname] - if (value) { - return value - } - if (!value) { - for (const target in hostMap) { - if (target.indexOf('*') < 0) { - continue - } - // 正则表达式匹配 - if (hostname.match(target)) { - return hostMap[target] - } - } - } -} -module.exports = { - isMatched, - domainRegexply, - domainMapRegexply, - matchHostname -}