mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-08 09:08:47 +00:00
Downloader: Use Headers.getDate() rather than parsing the date manually.
This commit is contained in:
parent
759afdd5ca
commit
93e4e23f60
1 changed files with 6 additions and 10 deletions
|
@ -50,7 +50,6 @@ import okhttp3.HttpUrl;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import okhttp3.internal.http.HttpDate;
|
|
||||||
|
|
||||||
public class Downloader {
|
public class Downloader {
|
||||||
private final File cacheDir;
|
private final File cacheDir;
|
||||||
|
@ -84,15 +83,12 @@ public class Downloader {
|
||||||
final Request.Builder request = new Request.Builder();
|
final Request.Builder request = new Request.Builder();
|
||||||
request.url(remoteUrl);
|
request.url(remoteUrl);
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
final String expiresHeader = meta.get("Expires");
|
final Date expires = meta.getDate("Expires");
|
||||||
if (expiresHeader != null) {
|
if (expires != null && System.currentTimeMillis() < expires.getTime()) {
|
||||||
final Date expires = HttpDate.parse(expiresHeader);
|
log.info("Download '{}' skipped; using cached copy.", remoteUrl);
|
||||||
if (expires != null && System.currentTimeMillis() < expires.getTime()) {
|
future.set(HttpURLConnection.HTTP_NOT_MODIFIED);
|
||||||
log.info("Download '{}' skipped; using cached copy.", remoteUrl);
|
semaphore.release();
|
||||||
future.set(HttpURLConnection.HTTP_NOT_MODIFIED);
|
return future;
|
||||||
semaphore.release();
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String lastModified = meta.get("Last-Modified");
|
final String lastModified = meta.get("Last-Modified");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue