If lastModified is not a date, assume it is an ETAg
This commit is contained in:
parent
20ccfbb809
commit
8b486e22d2
|
@ -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) {
|
||||
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(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 (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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue