1
0
mirror of https://github.com/DNSCrypt/dnscrypt-proxy.git synced 2024-12-29 00:30:30 +01:00

cleanup: xtransport: move onion check earlier to fail fast

This commit is contained in:
Markus Linnala 2019-10-16 13:17:57 +03:00 committed by Frank Denis
parent df03065eaf
commit 345ec56cab

View File

@ -211,6 +211,10 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
url2.RawQuery = qs.Encode()
url = &url2
}
host, _ := ExtractHostAndPort(url.Host, 0)
if xTransport.proxyDialer == nil && strings.HasSuffix(host, ".onion") {
return nil, 0, errors.New("Onion service is not reachable without Tor")
}
req := &http.Request{
Method: method,
URL: url,
@ -223,10 +227,6 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
req.Body = bc
}
var err error
host, _ := ExtractHostAndPort(url.Host, 0)
if xTransport.proxyDialer == nil && strings.HasSuffix(host, ".onion") {
return nil, 0, errors.New("Onion service is not reachable without Tor")
}
resolveByProxy := false
if xTransport.proxyDialer != nil || xTransport.httpProxyFunction != nil {
resolveByProxy = true