Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: 拦截配置,支持排除配置(exclusions)了 #356

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/mitmproxy/src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions packages/mitmproxy/src/utils/util.match.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}

Expand Down