From 9b9c42d3b07b51277ad492fd10c976c6631b2a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Sat, 28 Sep 2024 22:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mitmproxy/src/options.js | 9 ++-- .../mitmproxy/src/utils/util.match.old.js | 53 ------------------- 2 files changed, 3 insertions(+), 59 deletions(-) delete mode 100644 packages/mitmproxy/src/utils/util.match.old.js 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 -}