am ef3cafe1: (-s ours) am 2bffbe7e: Merge "Stop logging slow requests outside of debug logs."
* commit 'ef3cafe15faf2b295059b1c2784f8b88998d46ff':
diff --git a/pom.xml b/pom.xml
index 6b8072e..7c37e0f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
- <version>2.2</version>
+ <version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
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 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 @@
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 @@
}
/**
+ * 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>.
diff --git a/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java b/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
index 8bd98aa..917ddb4 100644
--- a/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
+++ b/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
@@ -8,7 +8,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.robolectric.Robolectric;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.*;
@@ -20,7 +20,7 @@
@Before public void setUp() throws Exception {
mMockImageLoader = new MockImageLoader();
- mNIV = new NetworkImageView(Robolectric.application);
+ mNIV = new NetworkImageView(RuntimeEnvironment.application);
}
@Test public void setImageUrl_requestsImage() {