日志小调整。

pull/287/head
王良 8 months ago
parent 15d4a88e15
commit 8b54345bc1

@ -4,7 +4,7 @@ const log = require('../../../utils/util.log')
const DnsUtil = require('../../dns/index') const DnsUtil = require('../../dns/index')
const localIP = '127.0.0.1' const localIP = '127.0.0.1'
const defaultDns = require('dns') const defaultDns = require('dns')
const matchUtil = require('../../../utils/util.match') // const matchUtil = require('../../../utils/util.match')
const speedTest = require('../../speed/index.js') const speedTest = require('../../speed/index.js')
function isSslConnect (sslConnectInterceptors, req, cltSocket, head) { function isSslConnect (sslConnectInterceptors, req, cltSocket, head) {
for (const intercept of sslConnectInterceptors) { for (const intercept of sslConnectInterceptors) {
@ -31,7 +31,7 @@ module.exports = function createConnectHandler (sslConnectInterceptor, middlewar
} }
console.log('sni config', sniConfig) console.log('sni config', sniConfig)
const sniRegexpMap = matchUtil.domainMapRegexply(sniConfig) // const sniRegexpMap = matchUtil.domainMapRegexply(sniConfig)
return function connectHandler (req, cltSocket, head) { return function connectHandler (req, cltSocket, head) {
// eslint-disable-next-line node/no-deprecated-api // eslint-disable-next-line node/no-deprecated-api
const srvUrl = url.parse(`https://${req.url}`) const srvUrl = url.parse(`https://${req.url}`)
@ -45,12 +45,12 @@ module.exports = function createConnectHandler (sslConnectInterceptor, middlewar
}) })
} else { } else {
log.info('不拦截请求:', hostname) log.info('不拦截请求:', hostname)
connect(req, cltSocket, head, hostname, srvUrl.port, dnsConfig, sniRegexpMap) connect(req, cltSocket, head, hostname, srvUrl.port, dnsConfig/*, sniRegexpMap */)
} }
} }
} }
function connect (req, cltSocket, head, hostname, port, dnsConfig, sniRegexpMap) { function connect (req, cltSocket, head, hostname, port, dnsConfig/*, sniRegexpMap */) {
// tunneling https // tunneling https
// log.info('connect:', hostname, port) // log.info('connect:', hostname, port)
const start = new Date().getTime() const start = new Date().getTime()

@ -110,7 +110,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
function onFree () { function onFree () {
const url = `${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}` const url = `${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}`
const start = new Date().getTime() const start = new Date().getTime()
log.info('代理请求:', url, rOptions.method) log.info('代理请求:', url, rOptions.method, rOptions.servername ? ', sni: ' + rOptions.servername : '')
let isDnsIntercept let isDnsIntercept
if (dnsConfig) { if (dnsConfig) {
const dns = DnsUtil.hasDnsLookup(dnsConfig, rOptions.hostname) const dns = DnsUtil.hasDnsLookup(dnsConfig, rOptions.hostname)

@ -106,14 +106,14 @@ function deleteNullItems (target) {
} }
function matchHostnameAll (hostMap, hostname, action) { function matchHostnameAll (hostMap, hostname, action) {
// log.debug('matchHostnameAll:', action, hostMap) // log.debug('matchHostname-all:', action, hostMap)
if (hostMap == null) { if (hostMap == null) {
log.warn(`matchHostnameAll: ${action}: '${hostname}', hostMap is null`) log.warn(`matchHostname-all: ${action}: '${hostname}', hostMap is null`)
return null return null
} }
if (hostMap.origin == null) { if (hostMap.origin == null) {
log.warn(`matchHostnameAll: ${action}: '${hostname}', hostMap.origin is null`) log.warn(`matchHostname-all: ${action}: '${hostname}', hostMap.origin is null`)
return null return null
} }
@ -139,7 +139,7 @@ function matchHostnameAll (hostMap, hostname, action) {
// 正则表达式匹配 // 正则表达式匹配
if (hostname.match(regexp)) { if (hostname.match(regexp)) {
value = hostMap[target] value = hostMap[target]
log.info(`matchHostnameOne: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`) log.info(`matchHostname-one: ${action}: '${hostname}' -> '${target}': ${JSON.stringify(value)}`)
values = merge(values, value) values = merge(values, value)
} }
} }
@ -148,28 +148,28 @@ function matchHostnameAll (hostMap, hostname, action) {
// 优先级2 // 优先级2
value = hostMap.origin['*' + hostname] value = hostMap.origin['*' + hostname]
if (value) { if (value) {
log.info(`matchHostnameOne: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`) log.info(`matchHostname-one: ${action}: '${hostname}' -> '*${hostname}': ${JSON.stringify(value)}`)
values = merge(values, value) values = merge(values, value)
} }
// 优先级3 // 优先级3
value = hostMap.origin['*.' + hostname] value = hostMap.origin['*.' + hostname]
if (value) { if (value) {
log.info(`matchHostnameOne: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`) log.info(`matchHostname-one: ${action}: '${hostname}' -> '*.${hostname}': ${JSON.stringify(value)}`)
values = merge(values, value) values = merge(values, value)
} }
// 优先级4最高优先级高的配置可以覆盖优先级低的配置甚至有空配置时可以移除已有配置 // 优先级4最高优先级高的配置可以覆盖优先级低的配置甚至有空配置时可以移除已有配置
value = hostMap.origin[hostname] value = hostMap.origin[hostname]
if (value) { if (value) {
log.info(`matchHostnameOne: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`) log.info(`matchHostname-one: ${action}: '${hostname}' -> '${hostname}': ${JSON.stringify(value)}`)
values = merge(values, value) values = merge(values, value)
} }
if (!lodash.isEmpty(values)) { if (!lodash.isEmpty(values)) {
deleteNullItems(values) deleteNullItems(values)
log.info(`matchHostnameAll: ${action}: '${hostname}':`, JSON.stringify(values)) log.info(`matchHostname-all: ${action}: '${hostname}':`, JSON.stringify(values))
return values return values
} else { } else {
log.debug(`matchHostnameAll: ${action}: '${hostname}' Not-Matched`) log.debug(`matchHostname-all: ${action}: '${hostname}' Not-Matched`)
} }
} }

Loading…
Cancel
Save