From f3353fbb1db16c72ca28747b0e721e18553c605d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Sat, 14 Sep 2024 12:12:55 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E6=8B=A6=E6=88=AA=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E6=8E=92=E9=99=A4=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=88`exclusions`=EF=BC=89=20(#356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mitmproxy/src/options.js | 15 +++++++++++++++ packages/mitmproxy/src/utils/util.match.js | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/mitmproxy/src/options.js b/packages/mitmproxy/src/options.js index ad07dcb..767cb2c 100644 --- a/packages/mitmproxy/src/options.js +++ b/packages/mitmproxy/src/options.js @@ -116,6 +116,21 @@ module.exports = (serverConfig) => { const interceptOpt = interceptOpts[regexp] // interceptOpt.key = regexp + // 添加exclusions字段,用于排除某些路径 + // @since 1.8.5 + if (Array.isArray(interceptOpt.exclusions) && interceptOpt.exclusions.length > 0) { + let isExcluded = false + for (const exclusion of interceptOpt.exclusions) { + if (matchUtil.isMatched(rOptions.path, exclusion)) { + log.debug(`拦截器配置排除了path:${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}, exclusion: '${exclusion}', interceptOpt:`, interceptOpt) + isExcluded = true + } + } + if (isExcluded) { + continue + } + } + log.debug(`拦截器匹配path成功:${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}, regexp: ${regexp}, interceptOpt:`, interceptOpt) // log.info(`interceptor matched, regexp: '${regexp}' =>`, JSON.stringify(interceptOpt), ', url:', url) diff --git a/packages/mitmproxy/src/utils/util.match.js b/packages/mitmproxy/src/utils/util.match.js index 976f4b9..29db2db 100644 --- a/packages/mitmproxy/src/utils/util.match.js +++ b/packages/mitmproxy/src/utils/util.match.js @@ -151,7 +151,7 @@ function matchHostnameAll (hostMap, hostname, action) { // 正则表达式匹配 if (hostname.match(regexp)) { value = hostMap[target] - log.info(`matchHostname-one: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`) + log.debug(`matchHostname-one: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`) values = merge(values, value) } } @@ -160,19 +160,19 @@ function matchHostnameAll (hostMap, hostname, action) { // 优先级:2 value = hostMap.origin['*' + hostname] if (value) { - log.info(`matchHostname-one: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`) + log.debug(`matchHostname-one: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`) values = merge(values, value) } // 优先级:3 value = hostMap.origin['*.' + hostname] if (value) { - log.info(`matchHostname-one: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`) + log.debug(`matchHostname-one: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`) values = merge(values, value) } // 优先级:4,最高(注:优先级高的配置,可以覆盖优先级低的配置,甚至有空配置时,可以移除已有配置) value = hostMap.origin[hostname] if (value) { - log.info(`matchHostname-one: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`) + log.debug(`matchHostname-one: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`) values = merge(values, value) }