optimize: 代理请求使用了DNS获取到的IP时,添加响应头 `DS-Lookup`,返回当前所使用的IP。
parent
a5f2b9565c
commit
b9a53442b2
|
@ -62,7 +62,7 @@ function connect (req, cltSocket, head, hostname, port, dnsConfig) {
|
|||
if (dnsConfig && dnsConfig.providers) {
|
||||
const dns = DnsUtil.hasDnsLookup(dnsConfig, hostname)
|
||||
if (dns) {
|
||||
options.lookup = dnsLookup.createLookupFunc(dns, 'connect', hostport, isDnsIntercept)
|
||||
options.lookup = dnsLookup.createLookupFunc(null, dns, 'connect', hostport, isDnsIntercept)
|
||||
}
|
||||
}
|
||||
const proxySocket = net.connect(options, () => {
|
||||
|
|
|
@ -122,7 +122,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
|
|||
}
|
||||
}
|
||||
if (dns) {
|
||||
rOptions.lookup = dnsLookup.createLookupFunc(dns, 'request url', url, isDnsIntercept)
|
||||
rOptions.lookup = dnsLookup.createLookupFunc(res, dns, 'request url', url, isDnsIntercept)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ const log = require('../../../utils/util.log')
|
|||
const defaultDns = require('dns')
|
||||
|
||||
module.exports = {
|
||||
createLookupFunc: function (dns, action, target, isDnsIntercept) {
|
||||
createLookupFunc: function (res, dns, action, target, isDnsIntercept) {
|
||||
target = target ? (', target: ' + target) : ''
|
||||
|
||||
return (hostname, options, callback) => {
|
||||
|
@ -12,6 +12,7 @@ module.exports = {
|
|||
const aliveIpObj = tester.pickFastAliveIpObj()
|
||||
if (aliveIpObj) {
|
||||
log.info(`----- ${action}: ${hostname}, use alive ip from dns '${aliveIpObj.dns}': ${aliveIpObj.host}${target} -----`)
|
||||
if (res) res.setHeader('DS-Lookup', `IpTester: ${aliveIpObj.host}(${aliveIpObj.dns})`)
|
||||
callback(null, aliveIpObj.host, 4)
|
||||
return
|
||||
} else {
|
||||
|
@ -41,6 +42,7 @@ module.exports = {
|
|||
}
|
||||
if (isTestFailedIp === false) {
|
||||
log.info(`----- ${action}: ${hostname}, use ip from dns '${dns.name}': ${ip}${target} -----`)
|
||||
if (res) res.setHeader('DS-Lookup', `DNS: ${ip.host}(${dns.name})`)
|
||||
callback(null, ip, 4)
|
||||
return
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue