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
1 changed files with 4 additions and 4 deletions

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