diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-01-30 12:43:27 +0100 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2016-01-30 18:30:48 +0100 |
commit | 8b486e22d2483c0b6957dcc7302aab53ac1a0541 (patch) | |
tree | cfbea1c18b95e95d4aed078ad165e0ff16912183 /core/src/main/java | |
parent | 20ccfbb809cef53628bb6d05925e8e2d54c4cc36 (diff) | |
download | AntennaPod-8b486e22d2483c0b6957dcc7302aab53ac1a0541.zip |
If lastModified is not a date, assume it is an ETAg
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java | 22 |
1 files changed, 14 insertions, 8 deletions
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 d0bd019f6..0f083f659 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 @@ -8,7 +8,6 @@ import com.squareup.okhttp.Protocol; import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import com.squareup.okhttp.ResponseBody; -import com.squareup.okhttp.internal.http.HttpDate; import org.apache.commons.io.IOUtils; @@ -28,6 +27,7 @@ import java.util.Date; import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.feed.FeedImage; +import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.URIUtil; @@ -67,13 +67,19 @@ public class HttpDownloader extends Downloader { final URI uri = URIUtil.getURIFromRequestUrl(request.getSource()); Request.Builder httpReq = new Request.Builder().url(uri.toURL()) .header("User-Agent", ClientConfig.USER_AGENT); - if(request.getIfModifiedSince() > 0) { - long threeDaysAgo = System.currentTimeMillis() - 1000*60*60*24*3; - if(request.getIfModifiedSince() > threeDaysAgo) { - Date date = new Date(request.getIfModifiedSince()); - String httpDate = HttpDate.format(date); - Log.d(TAG, "addHeader(\"If-Modified-Since\", \"" + httpDate + "\")"); - httpReq.addHeader("If-Modified-Since", httpDate); + if(request.getLastModified() != null) { + String lastModified = request.getLastModified(); + Date lastModifiedDate = DateUtils.parse(lastModified); + if(lastModifiedDate != null) { + long threeDaysAgo = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 3; + if (lastModifiedDate.getTime() > threeDaysAgo) { + Log.d(TAG, "addHeader(\"If-Modified-Since\", \"" + lastModified + "\")"); + httpReq.addHeader("If-Modified-Since", lastModified); + } + } else { + String eTag = lastModified; + Log.d(TAG, "addHeader(\"If-None-Match\", \"" + eTag + "\")"); + httpReq.addHeader("If-None-Match", eTag); } } |