diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js index 05963b0..469256c 100644 --- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js +++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js @@ -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, () => { diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js index 1a25321..492e52b 100644 --- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js +++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js @@ -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) } } diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js index e434824..9efe2f4 100644 --- a/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js +++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js @@ -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 {