If lastModified is not a date, assume it is an ETAg

This commit is contained in:
Martin Fietz 2016-01-30 12:43:27 +01:00
parent 20ccfbb809
commit 8b486e22d2
1 changed files with 14 additions and 8 deletions

View File

@ -8,7 +8,6 @@ import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.Request; import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response; import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody; import com.squareup.okhttp.ResponseBody;
import com.squareup.okhttp.internal.http.HttpDate;
import org.apache.commons.io.IOUtils; 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.ClientConfig;
import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.feed.FeedImage; 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.DownloadError;
import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.URIUtil; import de.danoeh.antennapod.core.util.URIUtil;
@ -67,13 +67,19 @@ public class HttpDownloader extends Downloader {
final URI uri = URIUtil.getURIFromRequestUrl(request.getSource()); final URI uri = URIUtil.getURIFromRequestUrl(request.getSource());
Request.Builder httpReq = new Request.Builder().url(uri.toURL()) Request.Builder httpReq = new Request.Builder().url(uri.toURL())
.header("User-Agent", ClientConfig.USER_AGENT); .header("User-Agent", ClientConfig.USER_AGENT);
if(request.getIfModifiedSince() > 0) { if(request.getLastModified() != null) {
long threeDaysAgo = System.currentTimeMillis() - 1000*60*60*24*3; String lastModified = request.getLastModified();
if(request.getIfModifiedSince() > threeDaysAgo) { Date lastModifiedDate = DateUtils.parse(lastModified);
Date date = new Date(request.getIfModifiedSince()); if(lastModifiedDate != null) {
String httpDate = HttpDate.format(date); long threeDaysAgo = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 3;
Log.d(TAG, "addHeader(\"If-Modified-Since\", \"" + httpDate + "\")"); if (lastModifiedDate.getTime() > threeDaysAgo) {
httpReq.addHeader("If-Modified-Since", httpDate); 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);
} }
} }