diff --git a/packages/core/src/merge.js b/packages/core/src/merge.js index 64b760b..3c7888d 100644 --- a/packages/core/src/merge.js +++ b/packages/core/src/merge.js @@ -65,7 +65,7 @@ function doDiff (oldObj, newObj) { function deleteNullItems (target) { lodash.forEach(target, (item, key) => { - if (item == null) { + if (item == null || item === '[delete]') { delete target[key] } if (lodash.isObject(item)) { diff --git a/packages/gui/src/view/components/settings.vue b/packages/gui/src/view/components/settings.vue index f4ac91a..54a47b6 100644 --- a/packages/gui/src/view/components/settings.vue +++ b/packages/gui/src/view/components/settings.vue @@ -17,7 +17,7 @@ :style="{ height: '100%' }" > - +
diff --git a/packages/gui/src/view/pages/server.vue b/packages/gui/src/view/pages/server.vue index 229e56e..480a727 100644 --- a/packages/gui/src/view/pages/server.vue +++ b/packages/gui/src/view/pages/server.vue @@ -138,7 +138,6 @@ -
@@ -201,7 +200,6 @@ -
diff --git a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js index 57bf379..7c567d7 100644 --- a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js +++ b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js @@ -18,7 +18,7 @@ function matched (hostname, overWallTargetMap) { log.info(`matchHostname: matched overwall: '${hostname}' -> '${ret}' in pac.txt`) return true } else { - // log.debug(`matchHostname: matched overwall: Not-Matched '${hostname}' -> '${ret}' in pac.txt`) + log.debug(`matchHostname: matched overwall: Not-Matched '${hostname}' -> '${ret}' in pac.txt`) return false } } diff --git a/packages/mitmproxy/src/options.js b/packages/mitmproxy/src/options.js index 644ac52..1a925a3 100644 --- a/packages/mitmproxy/src/options.js +++ b/packages/mitmproxy/src/options.js @@ -70,7 +70,7 @@ module.exports = (config) => { const matchInterceptsOpts = {} for (const regexp in interceptOpts) { // 遍历拦截配置 const interceptOpt = interceptOpts[regexp] - interceptOpt.key = regexp + // interceptOpt.key = regexp if (regexp !== true && regexp !== 'true') { if (!matchUtil.isMatched(rOptions.path, regexp)) { continue diff --git a/packages/mitmproxy/src/utils/util.match.js b/packages/mitmproxy/src/utils/util.match.js index e5ebd6d..b77e80c 100644 --- a/packages/mitmproxy/src/utils/util.match.js +++ b/packages/mitmproxy/src/utils/util.match.js @@ -94,6 +94,16 @@ function merge (oldObj, newObj) { } }) } +function deleteNullItems (target) { + lodash.forEach(target, (item, key) => { + if (item == null || item === '[delete]') { + delete target[key] + } + if (lodash.isObject(item)) { + deleteNullItems(item) + } + }) +} function matchHostnameAll (hostMap, hostname, action) { // log.debug('matchHostnameAll:', action, hostMap) @@ -108,29 +118,9 @@ function matchHostnameAll (hostMap, hostname, action) { } let values = {} - let hasValue = false + let value - // 域名快速匹配:直接匹配 或者 两种前缀通配符匹配 - let value = hostMap.origin[hostname] - if (value) { - log.info(`matchHostnameAll: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`) - values = merge(values, value) - hasValue = true - } - value = hostMap.origin['*' + hostname] - if (value) { - log.info(`matchHostnameAll: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`) - values = merge(values, value) - hasValue = true - } - value = hostMap.origin['*.' + hostname] - if (value) { - log.info(`matchHostnameAll: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`) - values = merge(values, value) - hasValue = true - } - - // 通配符匹配 或 正则表达式匹配 + // 通配符匹配 或 正则表达式匹配(优先级:1,最低) for (const target in hostMap) { if (target === 'origin') { continue @@ -149,17 +139,37 @@ function matchHostnameAll (hostMap, hostname, action) { // 正则表达式匹配 if (hostname.match(regexp)) { value = hostMap[target] - // log.info(`matchHostname: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`) + log.info(`matchHostnameOne: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`) values = merge(values, value) - hasValue = true } } - if (hasValue) { - log.info(`*matchHostnameAll*: ${action}: '${hostname}':`, JSON.stringify(values)) + // 域名快速匹配:直接匹配 或者 两种前缀通配符匹配 + // 优先级:2 + value = hostMap.origin['*' + hostname] + if (value) { + log.info(`matchHostnameOne: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`) + values = merge(values, value) + } + // 优先级:3 + value = hostMap.origin['*.' + hostname] + if (value) { + log.info(`matchHostnameOne: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`) + values = merge(values, value) + } + // 优先级:4,最高(注:优先级高的配置,可以覆盖优先级低的配置,甚至有空配置时,可以移除已有配置) + value = hostMap.origin[hostname] + if (value) { + log.info(`matchHostnameOne: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`) + values = merge(values, value) + } + + if (!lodash.isEmpty(values)) { + deleteNullItems(values) + log.info(`matchHostnameAll: ${action}: '${hostname}':`, JSON.stringify(values)) return values } else { - log.debug(`*matchHostnameAll*: ${action}: '${hostname}' Not-Matched`) + log.debug(`matchHostnameAll: ${action}: '${hostname}' Not-Matched`) } }