Use a single instance of OkHttp everywhere
This commit is contained in:
parent
cb0decd901
commit
c50c8a96e8
@ -7,7 +7,7 @@ import com.readrops.readropslibrary.localfeed.atom.ATOMFeed;
|
||||
import com.readrops.readropslibrary.localfeed.json.JSONFeed;
|
||||
import com.readrops.readropslibrary.localfeed.rss.RSSFeed;
|
||||
import com.readrops.readropslibrary.localfeed.rss.RSSLink;
|
||||
import com.readrops.readropslibrary.utils.HttpBuilder;
|
||||
import com.readrops.readropslibrary.utils.HttpManager;
|
||||
import com.readrops.readropslibrary.utils.LibUtils;
|
||||
import com.readrops.readropslibrary.utils.UnknownFormatException;
|
||||
import com.squareup.moshi.JsonAdapter;
|
||||
@ -75,7 +75,8 @@ public class RSSQuery {
|
||||
}
|
||||
|
||||
private Response query(String url, Map<String, String> headers) throws IOException {
|
||||
OkHttpClient okHttpClient = HttpBuilder.getBuilder().build();
|
||||
OkHttpClient okHttpClient = HttpManager.getInstance().getOkHttpClient();
|
||||
HttpManager.getInstance().setCredentials(null);
|
||||
|
||||
Request.Builder builder = new Request.Builder().url(url);
|
||||
for (String header : headers.keySet()) {
|
||||
|
@ -1,23 +0,0 @@
|
||||
package com.readrops.readropslibrary.utils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public final class HttpBuilder {
|
||||
|
||||
private static OkHttpClient.Builder builder;
|
||||
|
||||
public static OkHttpClient.Builder getBuilder() {
|
||||
if (builder == null)
|
||||
builder = createOkHttpBuilder();
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static OkHttpClient.Builder createOkHttpBuilder() {
|
||||
return new OkHttpClient.Builder()
|
||||
.callTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(1, TimeUnit.HOURS);
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.readrops.readropslibrary.utils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.readrops.readropslibrary.services.Credentials;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -31,7 +33,7 @@ public class HttpManager {
|
||||
return okHttpClient;
|
||||
}
|
||||
|
||||
public void setCredentials(Credentials credentials) {
|
||||
public void setCredentials(@Nullable Credentials credentials) {
|
||||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
@ -63,7 +65,7 @@ public class HttpManager {
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
|
||||
if (credentials.getAuthorization() != null) {
|
||||
if (credentials != null && credentials.getAuthorization() != null) {
|
||||
request = request.newBuilder()
|
||||
.addHeader("Authorization", credentials.getAuthorization())
|
||||
.build();
|
||||
|
Loading…
x
Reference in New Issue
Block a user