Skip DNS resolution on Tor services

This commit is contained in:
Frank Denis 2019-04-14 11:18:14 +02:00
parent 0a535e28ab
commit 4b001e3b8e
1 changed files with 5 additions and 2 deletions

View File

@ -200,10 +200,14 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
}
var err error
host := url.Host
resolveByProxy := false
if strings.HasSuffix(host, ".onion") {
resolveByProxy = true
}
xTransport.cachedIPs.RLock()
cachedIP := xTransport.cachedIPs.cache[host]
xTransport.cachedIPs.RUnlock()
if !xTransport.ignoreSystemDNS || len(cachedIP) > 0 {
if !xTransport.ignoreSystemDNS || len(cachedIP) > 0 || resolveByProxy {
var resp *http.Response
start := time.Now()
resp, err = client.Do(req)
@ -242,7 +246,6 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
xTransport.cachedIPs.cache[host] = *foundIP
xTransport.cachedIPs.Unlock()
dlog.Debugf("[%s] IP address [%s] added to the cache", host, *foundIP)
start := time.Now()
resp, err := client.Do(req)
rtt := time.Since(start)