aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/android/volley/Request.java13
-rw-r--r--src/main/java/com/android/volley/toolbox/DiskBasedCache.java5
-rw-r--r--src/main/java/com/android/volley/toolbox/HurlStack.java19
3 files changed, 21 insertions, 16 deletions
diff --git a/src/main/java/com/android/volley/Request.java b/src/main/java/com/android/volley/Request.java
index 9832952..5b42d1f 100644
--- a/src/main/java/com/android/volley/Request.java
+++ b/src/main/java/com/android/volley/Request.java
@@ -90,12 +90,6 @@ public abstract class Request<T> implements Comparable<Request<T>> {
/** Whether or not a response has been delivered for this request yet. */
private boolean mResponseDelivered = false;
- // A cheap variant of request tracing used to dump slow requests.
- private long mRequestBirthTime = 0;
-
- /** Threshold at which we should log the request (even when debug logging is not enabled). */
- private static final long SLOW_REQUEST_THRESHOLD_MS = 3000;
-
/** The retry policy for this request. */
private RetryPolicy mRetryPolicy;
@@ -209,8 +203,6 @@ public abstract class Request<T> implements Comparable<Request<T>> {
public void addMarker(String tag) {
if (MarkerLog.ENABLED) {
mEventLog.add(tag, Thread.currentThread().getId());
- } else if (mRequestBirthTime == 0) {
- mRequestBirthTime = SystemClock.elapsedRealtime();
}
}
@@ -241,11 +233,6 @@ public abstract class Request<T> implements Comparable<Request<T>> {
mEventLog.add(tag, threadId);
mEventLog.finish(this.toString());
- } else {
- long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime;
- if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) {
- VolleyLog.d("%d ms: %s", requestTime, this.toString());
- }
}
}
diff --git a/src/main/java/com/android/volley/toolbox/DiskBasedCache.java b/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
index ff687d6..c76d39a 100644
--- a/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
+++ b/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
@@ -22,6 +22,7 @@ import com.android.volley.Cache;
import com.android.volley.VolleyLog;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
@@ -113,7 +114,7 @@ public class DiskBasedCache implements Cache {
File file = getFileForKey(key);
CountingInputStream cis = null;
try {
- cis = new CountingInputStream(new FileInputStream(file));
+ cis = new CountingInputStream(new BufferedInputStream(new FileInputStream(file)));
CacheHeader.readHeader(cis); // eat header
byte[] data = streamToBytes(cis, (int) (file.length() - cis.bytesRead));
return entry.toCacheEntry(data);
@@ -196,7 +197,7 @@ public class DiskBasedCache implements Cache {
pruneIfNeeded(entry.data.length);
File file = getFileForKey(key);
try {
- FileOutputStream fos = new FileOutputStream(file);
+ BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(file));
CacheHeader e = new CacheHeader(key, entry);
boolean success = e.writeHeader(fos);
if (!success) {
diff --git a/src/main/java/com/android/volley/toolbox/HurlStack.java b/src/main/java/com/android/volley/toolbox/HurlStack.java
index 31d57f0..1be202e 100644
--- a/src/main/java/com/android/volley/toolbox/HurlStack.java
+++ b/src/main/java/com/android/volley/toolbox/HurlStack.java
@@ -23,6 +23,7 @@ import com.android.volley.Request.Method;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.entity.BasicHttpEntity;
@@ -115,7 +116,9 @@ public class HurlStack implements HttpStack {
StatusLine responseStatus = new BasicStatusLine(protocolVersion,
connection.getResponseCode(), connection.getResponseMessage());
BasicHttpResponse response = new BasicHttpResponse(responseStatus);
- response.setEntity(entityFromConnection(connection));
+ if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
+ response.setEntity(entityFromConnection(connection));
+ }
for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
if (header.getKey() != null) {
Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
@@ -126,6 +129,20 @@ public class HurlStack implements HttpStack {
}
/**
+ * Checks if a response message contains a body.
+ * @see <a href="https://tools.ietf.org/html/rfc7230#section-3.3">RFC 7230 section 3.3</a>
+ * @param requestMethod request method
+ * @param responseCode response status code
+ * @return whether the response has a body
+ */
+ private static boolean hasResponseBody(int requestMethod, int responseCode) {
+ return requestMethod != Request.Method.HEAD
+ && !(HttpStatus.SC_CONTINUE <= responseCode && responseCode < HttpStatus.SC_OK)
+ && responseCode != HttpStatus.SC_NO_CONTENT
+ && responseCode != HttpStatus.SC_NOT_MODIFIED;
+ }
+
+ /**
* Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.