Refactor: Extract method getSocks5Proxy

This commit is contained in:
chimp1984 2020-12-13 14:52:06 -05:00
parent 77f46a0a5e
commit 3a2e4f1d69
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -104,14 +104,7 @@ public class HttpClientImpl implements HttpClient {
@Nullable String headerValue) throws IOException {
checkNotNull(baseUrl, "baseUrl must be set before calling requestWithGET");
Socks5Proxy socks5Proxy = null;
if (socks5ProxyProvider != null) {
// We use the custom socks5ProxyHttp. If not set we request socks5ProxyProvider.getSocks5ProxyBtc()
// which delivers the btc proxy if set, otherwise the internal proxy.
socks5Proxy = socks5ProxyProvider.getSocks5ProxyHttp();
if (socks5Proxy == null)
socks5Proxy = socks5ProxyProvider.getSocks5Proxy();
}
Socks5Proxy socks5Proxy = getSocks5Proxy(socks5ProxyProvider);
if (ignoreSocks5Proxy || socks5Proxy == null || baseUrl.contains("localhost")) {
log.debug("Use clear net for HttpClient. socks5Proxy={}, ignoreSocks5Proxy={}, baseUrl={}",
socks5Proxy, ignoreSocks5Proxy, baseUrl);
@ -122,6 +115,18 @@ public class HttpClientImpl implements HttpClient {
}
}
private Socks5Proxy getSocks5Proxy(Socks5ProxyProvider socks5ProxyProvider) {
Socks5Proxy socks5Proxy = null;
if (socks5ProxyProvider != null) {
// We use the custom socks5ProxyHttp. If not set we request socks5ProxyProvider.getSocks5ProxyBtc()
// which delivers the btc proxy if set, otherwise the internal proxy.
socks5Proxy = socks5ProxyProvider.getSocks5ProxyHttp();
if (socks5Proxy == null)
socks5Proxy = socks5ProxyProvider.getSocks5Proxy();
}
return socks5Proxy;
}
/**
* Make an HTTP Get request directly (not routed over socks5 proxy).
*/