diff --git a/src/main/java/com/binance/connector/client/utils/httpclient/HttpClientSingleton.java b/src/main/java/com/binance/connector/client/utils/httpclient/HttpClientSingleton.java index c784a0d0..8b0a5c2b 100644 --- a/src/main/java/com/binance/connector/client/utils/httpclient/HttpClientSingleton.java +++ b/src/main/java/com/binance/connector/client/utils/httpclient/HttpClientSingleton.java @@ -12,12 +12,12 @@ private HttpClientSingleton() { private static void createHttpClient(ProxyAuth proxy) { if (proxy == null) { - httpClient = new OkHttpClient(); + httpClient = new OkHttpClient(OkHttpClientBuilder.getBuilder()); } else { if (proxy.getAuth() == null) { - httpClient = new OkHttpClient.Builder().proxy(proxy.getProxy()).build(); + httpClient = OkHttpClientBuilder.getBuilder().proxy(proxy.getProxy()).build(); } else { - httpClient = new OkHttpClient.Builder().proxy(proxy.getProxy()).proxyAuthenticator(proxy.getAuth()).build(); + httpClient = OkHttpClientBuilder.getBuilder().proxy(proxy.getProxy()).proxyAuthenticator(proxy.getAuth()).build(); } } } diff --git a/src/main/java/com/binance/connector/client/utils/httpclient/OkHttpClientBuilder.java b/src/main/java/com/binance/connector/client/utils/httpclient/OkHttpClientBuilder.java new file mode 100644 index 00000000..f3fcb0ca --- /dev/null +++ b/src/main/java/com/binance/connector/client/utils/httpclient/OkHttpClientBuilder.java @@ -0,0 +1,18 @@ +package com.binance.connector.client.utils.httpclient; + +import okhttp3.OkHttpClient; + +public final class OkHttpClientBuilder { + private static OkHttpClient.Builder builder = new OkHttpClient.Builder(); + + private OkHttpClientBuilder() { + } + + public static void setBuilder(OkHttpClient.Builder builder) { + OkHttpClientBuilder.builder = builder; + } + + public static OkHttpClient.Builder getBuilder() { + return builder; + } +} diff --git a/src/main/java/com/binance/connector/client/utils/httpclient/WebSocketApiHttpClientSingleton.java b/src/main/java/com/binance/connector/client/utils/httpclient/WebSocketApiHttpClientSingleton.java index 672fb005..065107f6 100644 --- a/src/main/java/com/binance/connector/client/utils/httpclient/WebSocketApiHttpClientSingleton.java +++ b/src/main/java/com/binance/connector/client/utils/httpclient/WebSocketApiHttpClientSingleton.java @@ -3,7 +3,7 @@ import okhttp3.OkHttpClient; public final class WebSocketApiHttpClientSingleton { - private static final OkHttpClient httpClient = new OkHttpClient(); + private static final OkHttpClient httpClient = new OkHttpClient(OkHttpClientBuilder.getBuilder()); private WebSocketApiHttpClientSingleton() { } diff --git a/src/main/java/com/binance/connector/client/utils/httpclient/WebSocketStreamHttpClientSingleton.java b/src/main/java/com/binance/connector/client/utils/httpclient/WebSocketStreamHttpClientSingleton.java index d2462927..d6008970 100644 --- a/src/main/java/com/binance/connector/client/utils/httpclient/WebSocketStreamHttpClientSingleton.java +++ b/src/main/java/com/binance/connector/client/utils/httpclient/WebSocketStreamHttpClientSingleton.java @@ -3,7 +3,7 @@ import okhttp3.OkHttpClient; public final class WebSocketStreamHttpClientSingleton { - private static final OkHttpClient httpClient = new OkHttpClient(); + private static final OkHttpClient httpClient = new OkHttpClient(OkHttpClientBuilder.getBuilder()); private WebSocketStreamHttpClientSingleton() { }