Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
@@ -22,6 +22,7 @@ import java.net.NoRouteToHostException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
|
||||
@@ -51,7 +52,7 @@ public class HttpRequestImpl implements HttpRequest {
|
||||
static final OkHttpClient DEFAULT_CLIENT = new OkHttpClient.Builder().dispatcher(getDispatcher()).build();
|
||||
|
||||
@VisibleForTesting
|
||||
static OkHttpClient client = DEFAULT_CLIENT;
|
||||
static Call.Factory client = DEFAULT_CLIENT;
|
||||
|
||||
private Call call;
|
||||
|
||||
@@ -105,12 +106,8 @@ public class HttpRequestImpl implements HttpRequest {
|
||||
HttpLogger.logEnabled = enabled;
|
||||
}
|
||||
|
||||
public static void setOkHttpClient(@Nullable OkHttpClient okHttpClient) {
|
||||
if (okHttpClient != null) {
|
||||
HttpRequestImpl.client = okHttpClient;
|
||||
} else {
|
||||
HttpRequestImpl.client = DEFAULT_CLIENT;
|
||||
}
|
||||
public static void setOkHttpClient(@Nullable Call.Factory client) {
|
||||
HttpRequestImpl.client = Objects.requireNonNullElse(client, DEFAULT_CLIENT);
|
||||
}
|
||||
|
||||
private static class OkHttpCallback implements Callback {
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.maplibre.android.module.http;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Call;
|
||||
import okio.Buffer;
|
||||
|
||||
/**
|
||||
@@ -39,15 +39,15 @@ public class HttpRequestUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OkHttpClient used for requesting map resources.
|
||||
* Set the OkHttp Call.Factory used for requesting map resources.
|
||||
* <p>
|
||||
* This configuration survives across mapView instances.
|
||||
* Reset the OkHttpClient to the default by passing null as parameter.
|
||||
* </p>
|
||||
*
|
||||
* @param client the OkHttpClient
|
||||
* @param client the OkHttp Call.Factory, typically OkHttpClient.
|
||||
*/
|
||||
public static void setOkHttpClient(@Nullable OkHttpClient client) {
|
||||
public static void setOkHttpClient(@Nullable Call.Factory client) {
|
||||
HttpRequestImpl.setOkHttpClient(client);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user