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

Custom OkHttpClient #68

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion centrifuge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ publishing {
}

dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
api 'com.squareup.okhttp3:okhttp:4.10.0'
implementation 'com.google.protobuf:protobuf-javalite:3.21.12'
implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ private void _connect() {
this.ws.cancel();
}

OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder();
OkHttpClient.Builder okHttpBuilder;
if (opts.getOkHttpClient() != null) {
okHttpBuilder = opts.getOkHttpClient().newBuilder();
} else {
okHttpBuilder = new OkHttpClient.Builder()
}

Dns dns = opts.getDns();
if (dns != null) {
Expand Down Expand Up @@ -532,7 +537,7 @@ private ServerSubscription getServerSub(String channel) {
* Create new subscription to channel with SubscriptionOptions and SubscriptionEventListener
*
* @param channel: to create Subscription for.
* @param options: to pass SubscriptionOptions, e.g. token.
* @param options: to pass SubscriptionOptions, e.g. token.
* @param listener: to pass event handler.
* @return Subscription.
* @throws DuplicateSubscriptionException if Subscription already exists in internal registry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.net.Proxy;
import java.util.Map;

import okhttp3.OkHttpClient;

/**
* Configuration for a {@link Client} instance.
*/
Expand Down Expand Up @@ -164,7 +166,10 @@ public Proxy getProxy() {

/**
* Set proxy credentials.
*
* @deprecated set up proxy in OkHttpClient and pass it to {@link #setOkHttpClient}
*/
@Deprecated
public void setProxyCredentials(String login, String password) {
this.proxyLogin = login;
this.proxyPassword = password;
Expand All @@ -183,11 +188,27 @@ public Dns getDns() {
}

/**
* Set custom DNS resolver..
* Set custom DNS resolver.
*
* @deprecated set DNS in OkHttpClient and pass it to {@link #setOkHttpClient}
*/
@Deprecated
public void setDns(Dns dns) {
this.dns = dns;
}

private Dns dns;

public OkHttpClient getOkHttpClient() {
return this.okHttpClient;
}

/**
* Set OkHttpClient. Can be used to configure custom network settings (DNS, proxy etc.).
*/
public void setOkHttpClient(OkHttpClient okHttpClient) {
this.okHttpClient = okHttpClient;
}

private OkHttpClient okHttpClient;
}