From 55cf75def96983ef510657b03344d3facbf6aa94 Mon Sep 17 00:00:00 2001 From: Hans-Peter Lehmann Date: Thu, 28 May 2026 16:39:10 +0200 Subject: [PATCH] Add if-range header when downloading (#8491) ### Description Add if-range header when downloading. Only resume download if the server tells us that the file didn't change in the meantime. This can happen especially in the presence of dynamic ad insertion. Original idea by @bushnelb in #8441 ### Checklist - [x] I have read the contribution guidelines: https://github.com/AntennaPod/AntennaPod/blob/develop/CONTRIBUTING.md#submit-a-pull-request - [x] I have performed a self-review of my code, going through my changes line by line and carefully considering why this line change is necessary - [x] I have run the automated code checks using `./gradlew checkstyle lint` - [x] My code follows the style guidelines of the AntennaPod project: https://antennapod.org/contribute/develop/app/code-style - [x] I have mentioned the corresponding issue and the relevant keyword (e.g., "Closes: #xy") in the description (see https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) - [x] If it is a core feature, I have added automated tests Co-authored-by: bushnelb <134662243+bushnelb@users.noreply.github.com> --- .../net/download/service/feed/remote/HttpDownloader.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/remote/HttpDownloader.java b/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/remote/HttpDownloader.java index 2a99c2bbb..4ce2960f3 100644 --- a/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/remote/HttpDownloader.java +++ b/net/download/service/src/main/java/de/danoeh/antennapod/net/download/service/feed/remote/HttpDownloader.java @@ -92,6 +92,11 @@ public class HttpDownloader extends Downloader { request.setSoFar(destination.length()); httpReq.addHeader("Range", "bytes=" + request.getSoFar() + "-"); Log.d(TAG, "Adding range header: " + request.getSoFar()); + // Only continue if the etag matches, otherwise the file might have changed + if (!TextUtils.isEmpty(request.getLastModified())) { + httpReq.addHeader("If-Range", request.getLastModified()); + Log.d(TAG, "Adding If-Range header: " + request.getLastModified()); + } } Response response = newCall(httpReq);