aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/android/volley
diff options
context:
space:
mode:
authorRalph Bergmann <ralph@the4thfloor.eu>2014-09-21 22:09:33 +0200
committerFicus Kirkpatrick <ficus@android.com>2015-02-15 09:09:05 -0800
commit9324df1b8046548587ffec89ec755264f6fbb097 (patch)
tree0f0cb0b835925767038340745b0faf82bce15996 /src/main/java/com/android/volley
parent3ac982d9455cb18d1c9ca10e695770d72fe21c90 (diff)
downloadvolley-9324df1b8046548587ffec89ec755264f6fbb097.tar.gz
Uses the "Last-Modified" header for "If-Modified-Since"
Uses the "Last-Modified" header for "If-Modified-Since" see http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.4 Change-Id: I0f5e9b45f4f79d7c1b286e465f9750dcd71b6bfd Signed-off-by: Ralph Bergmann <ralph@the4thfloor.eu>
Diffstat (limited to 'src/main/java/com/android/volley')
-rw-r--r--src/main/java/com/android/volley/Cache.java3
-rw-r--r--src/main/java/com/android/volley/toolbox/BasicNetwork.java4
-rw-r--r--src/main/java/com/android/volley/toolbox/DiskBasedCache.java13
-rw-r--r--src/main/java/com/android/volley/toolbox/HttpHeaderParser.java7
4 files changed, 25 insertions, 2 deletions
diff --git a/src/main/java/com/android/volley/Cache.java b/src/main/java/com/android/volley/Cache.java
index eafd118..f1ec757 100644
--- a/src/main/java/com/android/volley/Cache.java
+++ b/src/main/java/com/android/volley/Cache.java
@@ -74,6 +74,9 @@ public interface Cache {
/** Date of this response as reported by the server. */
public long serverDate;
+ /** The last modified date for the requested object. */
+ public long lastModified;
+
/** TTL for this record. */
public long ttl;
diff --git a/src/main/java/com/android/volley/toolbox/BasicNetwork.java b/src/main/java/com/android/volley/toolbox/BasicNetwork.java
index bc1cfdb..4b1603b 100644
--- a/src/main/java/com/android/volley/toolbox/BasicNetwork.java
+++ b/src/main/java/com/android/volley/toolbox/BasicNetwork.java
@@ -212,8 +212,8 @@ public class BasicNetwork implements Network {
headers.put("If-None-Match", entry.etag);
}
- if (entry.serverDate > 0) {
- Date refTime = new Date(entry.serverDate);
+ if (entry.lastModified > 0) {
+ Date refTime = new Date(entry.lastModified);
headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
}
}
diff --git a/src/main/java/com/android/volley/toolbox/DiskBasedCache.java b/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
index b283788..036b55a 100644
--- a/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
+++ b/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
@@ -349,6 +349,9 @@ public class DiskBasedCache implements Cache {
/** Date of this response as reported by the server. */
public long serverDate;
+ /** The last modified date for the requested object. */
+ public long lastModified;
+
/** TTL for this record. */
public long ttl;
@@ -370,6 +373,7 @@ public class DiskBasedCache implements Cache {
this.size = entry.data.length;
this.etag = entry.etag;
this.serverDate = entry.serverDate;
+ this.lastModified = entry.lastModified;
this.ttl = entry.ttl;
this.softTtl = entry.softTtl;
this.responseHeaders = entry.responseHeaders;
@@ -396,6 +400,13 @@ public class DiskBasedCache implements Cache {
entry.ttl = readLong(is);
entry.softTtl = readLong(is);
entry.responseHeaders = readStringStringMap(is);
+
+ try {
+ entry.lastModified = readLong(is);
+ } catch (EOFException e) {
+ // the old cache entry format doesn't know lastModified
+ }
+
return entry;
}
@@ -407,6 +418,7 @@ public class DiskBasedCache implements Cache {
e.data = data;
e.etag = etag;
e.serverDate = serverDate;
+ e.lastModified = lastModified;
e.ttl = ttl;
e.softTtl = softTtl;
e.responseHeaders = responseHeaders;
@@ -426,6 +438,7 @@ public class DiskBasedCache implements Cache {
writeLong(os, ttl);
writeLong(os, softTtl);
writeStringStringMap(responseHeaders, os);
+ writeLong(os, lastModified);
os.flush();
return true;
} catch (IOException e) {
diff --git a/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java b/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java
index cb08432..e342c9e 100644
--- a/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java
+++ b/src/main/java/com/android/volley/toolbox/HttpHeaderParser.java
@@ -42,6 +42,7 @@ public class HttpHeaderParser {
Map<String, String> headers = response.headers;
long serverDate = 0;
+ long lastModified = 0;
long serverExpires = 0;
long softExpire = 0;
long maxAge = 0;
@@ -79,6 +80,11 @@ public class HttpHeaderParser {
serverExpires = parseDateAsEpoch(headerValue);
}
+ headerValue = headers.get("Last-Modified");
+ if (headerValue != null) {
+ lastModified = parseDateAsEpoch(headerValue);
+ }
+
serverEtag = headers.get("ETag");
// Cache-Control takes precedence over an Expires header, even if both exist and Expires
@@ -96,6 +102,7 @@ public class HttpHeaderParser {
entry.softTtl = softExpire;
entry.ttl = entry.softTtl;
entry.serverDate = serverDate;
+ entry.lastModified = lastModified;
entry.responseHeaders = headers;
return entry;