Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuning OkHttpClient settings #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down