Skip to content

Commit

Permalink
optimize: 当请求匹配到了增强功能时,添加响应头 'DS-Overwall',标识请求FanQ了,并知道是匹配到配置还是PAC。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Sep 13, 2024
1 parent 24de95f commit 0e8f3a9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/mitmproxy/src/lib/proxy/middleware/overwall.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ let pacClient = null
function matched (hostname, overWallTargetMap) {
const ret1 = matchUtil.matchHostname(overWallTargetMap, hostname, 'matched overwall')
if (ret1) {
return true
return 'overwall config'
}
if (pacClient == null) {
return false
}
const ret = pacClient.FindProxyForURL('https://' + hostname, hostname)
if (ret && ret.indexOf('PROXY ') === 0) {
log.info(`matchHostname: matched overwall: '${hostname}' -> '${ret}' in pac.txt`)
return true
return 'overwall pac'
} else {
log.debug(`matchHostname: matched overwall: Not-Matched '${hostname}' -> '${ret}' in pac.txt`)
return false
Expand Down Expand Up @@ -153,7 +153,8 @@ function createOverwallMiddleware (overWallConfig) {
return
}
const hostname = rOptions.hostname
if (!matched(hostname, overWallTargetMap)) {
const matchedResult = matched(hostname, overWallTargetMap)
if (!matchedResult) {
return
}
const cacheKey = '__over_wall_proxy__'
Expand Down Expand Up @@ -205,6 +206,8 @@ function createOverwallMiddleware (overWallConfig) {
log.debug('OverWall choice:', JSON.stringify(context.requestCount))
}

res.setHeader('DS-Overwall', matchedResult)

return true
}
}
Expand Down

0 comments on commit 0e8f3a9

Please sign in to comment.