optimize: 是否需要代理的判断代码逻辑优化

pull/384/head
王良 2024-10-24 15:19:58 +08:00
parent 8dc5cfc37c
commit 21e46a4124
3 changed files with 8 additions and 15 deletions

View File

@ -148,14 +148,7 @@ function createOverwallMiddleware (overWallConfig) {
return { return {
sslConnectInterceptor: (req, cltSocket, head) => { sslConnectInterceptor: (req, cltSocket, head) => {
const hostname = req.url.split(':')[0] const hostname = req.url.split(':')[0]
const ret = matched(hostname, overWallTargetMap) return matched(hostname, overWallTargetMap)
if (ret == null) {
return null // 返回 null由下一个拦截器校验
}
if (ret === false) {
return false // 不拦截,预留这个判断,避免以后修改 matched 方法的代码出BUG
}
return true // 拦截
}, },
requestIntercept (context, req, res, ssl, next) { requestIntercept (context, req, res, ssl, next) {
const { rOptions, log, RequestCounter } = context const { rOptions, log, RequestCounter } = context
@ -164,7 +157,7 @@ function createOverwallMiddleware (overWallConfig) {
} }
const hostname = rOptions.hostname const hostname = rOptions.hostname
const matchedResult = matched(hostname, overWallTargetMap) const matchedResult = matched(hostname, overWallTargetMap)
if (matchedResult == null || matchedResult === false) { if (matchedResult == null || matchedResult === false || matchedResult === 'false') {
return return
} }
const cacheKey = '__over_wall_proxy__' const cacheKey = '__over_wall_proxy__'

View File

@ -9,11 +9,11 @@ const jsonApi = require('../../../json')
function isSslConnect (sslConnectInterceptors, req, cltSocket, head) { function isSslConnect (sslConnectInterceptors, req, cltSocket, head) {
for (const intercept of sslConnectInterceptors) { for (const intercept of sslConnectInterceptors) {
const ret = intercept(req, cltSocket, head) const ret = intercept(req, cltSocket, head)
log.debug(`拦截判断结果:${ret}, url: ${req.url}, intercept:`, intercept) log.debug('当前拦截器返回结果:', ret, `, url: ${req.url}, intercept:`, intercept)
if (ret === false || ret === true) { if (ret == null) {
return ret continue
} }
// continue return !(ret === false || ret === 'false')
} }
return false return false
} }

View File

@ -119,10 +119,10 @@ module.exports = (serverConfig) => {
const matched = matchUtil.matchHostname(intercepts, hostname, 'matched intercepts') const matched = matchUtil.matchHostname(intercepts, hostname, 'matched intercepts')
if ((!!matched) === true) { if ((!!matched) === true) {
log.debug(`拦截器拦截:${req.url}, matched:`, matched) log.debug(`拦截器拦截:${req.url}, matched:`, matched)
return true // 拦截 return matched // 拦截
} }
return null // 未匹配到任何拦截配置,由下一个拦截器判断 return null // 不在白名单中,也未配置在拦截功能中,跳过当前拦截器,由下一个拦截器判断
}, },
createIntercepts: (context) => { createIntercepts: (context) => {
const rOptions = context.rOptions const rOptions = context.rOptions