aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay Colline <rayc@google.com>2013-09-12 12:24:44 -0700
committerRay Colline <rayc@google.com>2013-09-12 12:24:44 -0700
commite8f5353b17aea6659dc3aa13223317b484d01483 (patch)
tree51fbd0df28fa4c5e1db1c3a727d89b629af596c6 /src
parent4c2fe1379f5d18bac2d27e89d4abb553e6f8d2e8 (diff)
downloadvolley-e8f5353b17aea6659dc3aa13223317b484d01483.tar.gz
Support no-content (204) requests in BasicNetwork.
When we get an empty response for say, a 204, we create a 0 byte response and pass it on to the NetworkResponse. Implementers of Request can then return appropriate Responses. The behavior before this change results in an NPE because we attempt to getContentLength() bytes from a null entity.. Change-Id: Ia5f92ffd99b8f3e88cc92dc50ba43c4721d83e79 Signed-off-by: Ray Colline <rayc@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/android/volley/toolbox/BasicNetwork.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/com/android/volley/toolbox/BasicNetwork.java b/src/com/android/volley/toolbox/BasicNetwork.java
index b3c7d45..3c1d5c7 100644
--- a/src/com/android/volley/toolbox/BasicNetwork.java
+++ b/src/com/android/volley/toolbox/BasicNetwork.java
@@ -101,7 +101,15 @@ public class BasicNetwork implements Network {
request.getCacheEntry().data, responseHeaders, true);
}
- responseContents = entityToBytes(httpResponse.getEntity());
+ // Some responses such as 204s do not have content. We must check.
+ if (httpResponse.getEntity() != null) {
+ responseContents = entityToBytes(httpResponse.getEntity());
+ } else {
+ // Add 0 byte response as a way of honestly representing a
+ // no-content request.
+ responseContents = new byte[0];
+ }
+
// if the request is slow, log it.
long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
logSlowRequests(requestLifetime, request, responseContents, statusLine);