aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRalph Bergmann <ralph@the4thfloor.eu>2014-09-22 01:21:09 +0200
committerRalph Bergmann <ralph@the4thfloor.eu>2014-10-07 13:03:00 +0200
commit19a40379b22eeb21991fb1c55cf45788e62188b2 (patch)
tree892fe5d90b9f077e42938a0e0d3918de0b72fce5 /src
parent5d0aec46bdff7ab15c02e2492837d97eda3a67e0 (diff)
downloadvolley-19a40379b22eeb21991fb1c55cf45788e62188b2.tar.gz
Copy cache header for 304 response
A HTTP 304 response does not have all header fields. We have to copy the header from the cache entry. see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5 Change-Id: I197864ad4f2b103edc4a718afea2a35127b7c203 Signed-off-by: Ralph Bergmann <ralph@the4thfloor.eu>
Diffstat (limited to 'src')
-rw-r--r--src/com/android/volley/toolbox/BasicNetwork.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/com/android/volley/toolbox/BasicNetwork.java b/src/com/android/volley/toolbox/BasicNetwork.java
index c82fc34..42696e2 100644
--- a/src/com/android/volley/toolbox/BasicNetwork.java
+++ b/src/com/android/volley/toolbox/BasicNetwork.java
@@ -20,6 +20,7 @@ import android.os.SystemClock;
import com.android.volley.AuthFailureError;
import com.android.volley.Cache;
+import com.android.volley.Cache.Entry;
import com.android.volley.Network;
import com.android.volley.NetworkError;
import com.android.volley.NetworkResponse;
@@ -97,9 +98,20 @@ public class BasicNetwork implements Network {
responseHeaders = convertHeaders(httpResponse.getAllHeaders());
// Handle cache validation.
if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
- return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED,
- request.getCacheEntry() == null ? null : request.getCacheEntry().data,
- responseHeaders, true);
+
+ Entry entry = request.getCacheEntry();
+ if (entry == null) {
+ return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null,
+ responseHeaders, true);
+ }
+
+ // A HTTP 304 response does not have all header fields. We
+ // have to use the header fields from the cache entry plus
+ // the new ones from the response.
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
+ entry.responseHeaders.putAll(responseHeaders);
+ return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, entry.data,
+ entry.responseHeaders, true);
}
// Some responses such as 204s do not have content. We must check.