diff options
author | ByteHamster <info@bytehamster.com> | 2020-03-16 01:09:32 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-03-16 10:48:29 +0100 |
commit | 3167c7a5d2333d94b81edc6d6b567bd4facad1ed (patch) | |
tree | 280e7d069467d560c3209fdbf5e23d087c49d064 /core | |
parent | c0a688ce5412586713e56c892b87d8b75884fc81 (diff) | |
download | AntennaPod-3167c7a5d2333d94b81edc6d6b567bd4facad1ed.zip |
Always add UserAgent to requests
Diffstat (limited to 'core')
5 files changed, 26 insertions, 7 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ChapterImageModelLoader.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ChapterImageModelLoader.java index bc0a06a07..36da11eca 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ChapterImageModelLoader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ChapterImageModelLoader.java @@ -71,7 +71,6 @@ public final class ChapterImageModelLoader implements ModelLoader<EmbeddedChapte callback.onDataReady(ByteBuffer.wrap(imageContent)); } else { Request.Builder httpReq = new Request.Builder(); - httpReq.header("User-Agent", ClientConfig.USER_AGENT); // Skipping would download the whole file httpReq.header("Range", "bytes=" + image.getPosition() + "-" + (image.getPosition() + image.getLength())); diff --git a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java index 9ee8c0fc1..97931237a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java @@ -554,9 +554,8 @@ public class GpodnetService { }.start(); } - private String executeRequest(@NonNull Request.Builder requestB) - throws GpodnetServiceException { - Request request = requestB.header("User-Agent", ClientConfig.USER_AGENT).build(); + private String executeRequest(@NonNull Request.Builder requestB) throws GpodnetServiceException { + Request request = requestB.build(); String responseString = null; Response response = null; ResponseBody body = null; @@ -584,7 +583,7 @@ public class GpodnetService { "request and credentials must not be null"); } - Request request = requestB.header("User-Agent", ClientConfig.USER_AGENT).build(); + Request request = requestB.build(); String result = null; ResponseBody body = null; try { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java b/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java new file mode 100644 index 000000000..5fcf8317d --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java @@ -0,0 +1,20 @@ +package de.danoeh.antennapod.core.service; + +import de.danoeh.antennapod.core.ClientConfig; +import okhttp3.Interceptor; +import okhttp3.Response; + +import java.io.IOException; + +public class UserAgentInterceptor implements Interceptor { + + public UserAgentInterceptor() { + } + + @Override + public Response intercept(Chain chain) throws IOException { + return chain.proceed(chain.request().newBuilder() + .header("User-Agent", ClientConfig.USER_AGENT) + .build()); + } +} diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java index ee0f8bd95..e0c23bdac 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java @@ -32,6 +32,7 @@ import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.service.UserAgentInterceptor; import de.danoeh.antennapod.core.storage.DBWriter; import okhttp3.Cache; import okhttp3.CipherSuite; @@ -116,6 +117,7 @@ public class AntennapodHttpClient { return response; }); builder.interceptors().add(new BasicAuthorizationInterceptor()); + builder.networkInterceptors().add(new UserAgentInterceptor()); // set cookie handler CookieManager cm = new CookieManager(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java index 46b8568c5..54b8d321a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java @@ -63,8 +63,7 @@ public class HttpDownloader extends Downloader { try { final URI uri = URIUtil.getURIFromRequestUrl(request.getSource()); - Request.Builder httpReq = new Request.Builder().url(uri.toURL()) - .header("User-Agent", ClientConfig.USER_AGENT); + Request.Builder httpReq = new Request.Builder().url(uri.toURL()); httpReq.tag(request); if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { // set header explicitly so that okhttp doesn't do transparent gzip |