Browse Source

optimize: 当请求匹配到了增强功能时,添加响应头 'DS-Overwall',标识请求FanQ了,并知道是匹配到配置还是PAC。

pull/356/head
王良 2 months ago
parent
commit
0e8f3a99e9
  1. 9
      packages/mitmproxy/src/lib/proxy/middleware/overwall.js

9
packages/mitmproxy/src/lib/proxy/middleware/overwall.js

@ -12,7 +12,7 @@ let pacClient = null
function matched (hostname, overWallTargetMap) { function matched (hostname, overWallTargetMap) {
const ret1 = matchUtil.matchHostname(overWallTargetMap, hostname, 'matched overwall') const ret1 = matchUtil.matchHostname(overWallTargetMap, hostname, 'matched overwall')
if (ret1) { if (ret1) {
return true return 'overwall config'
} }
if (pacClient == null) { if (pacClient == null) {
return false return false
@ -20,7 +20,7 @@ function matched (hostname, overWallTargetMap) {
const ret = pacClient.FindProxyForURL('https://' + hostname, hostname) const ret = pacClient.FindProxyForURL('https://' + hostname, hostname)
if (ret && ret.indexOf('PROXY ') === 0) { if (ret && ret.indexOf('PROXY ') === 0) {
log.info(`matchHostname: matched overwall: '${hostname}' -> '${ret}' in pac.txt`) log.info(`matchHostname: matched overwall: '${hostname}' -> '${ret}' in pac.txt`)
return true return 'overwall pac'
} else { } 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 return false
@ -153,7 +153,8 @@ function createOverwallMiddleware (overWallConfig) {
return return
} }
const hostname = rOptions.hostname const hostname = rOptions.hostname
if (!matched(hostname, overWallTargetMap)) { const matchedResult = matched(hostname, overWallTargetMap)
if (!matchedResult) {
return return
} }
const cacheKey = '__over_wall_proxy__' const cacheKey = '__over_wall_proxy__'
@ -205,6 +206,8 @@ function createOverwallMiddleware (overWallConfig) {
log.debug('OverWall choice:', JSON.stringify(context.requestCount)) log.debug('OverWall choice:', JSON.stringify(context.requestCount))
} }
res.setHeader('DS-Overwall', matchedResult)
return true return true
} }
} }

Loading…
Cancel
Save