diff options
| author | Elliott Hughes <enh@google.com> | 2012-07-31 09:47:31 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2012-07-31 09:47:31 -0700 |
| commit | 6a2cbb22c2ac526c71a80bc0ec54e6dac2e22bf6 (patch) | |
| tree | 90927ea68c81d3aa554fe225f570cb8a5347fc11 | |
| parent | 95ca54d1ae12653915882f3a3bf16746c676883b (diff) | |
| parent | 48b00f0d52cdce981c197e67e46a61af31d8648f (diff) | |
am 48b00f0d: Merge "HttpResponseCache should return 504, not 502."
* commit '48b00f0d52cdce981c197e67e46a61af31d8648f':
HttpResponseCache should return 504, not 502.
| -rw-r--r-- | luni/src/main/java/libcore/net/http/HttpEngine.java | 9 | ||||
| -rw-r--r-- | luni/src/test/java/libcore/net/http/HttpResponseCacheTest.java | 10 |
2 files changed, 10 insertions, 9 deletions
diff --git a/luni/src/main/java/libcore/net/http/HttpEngine.java b/luni/src/main/java/libcore/net/http/HttpEngine.java index 3e4b9d301d..a37095607c 100644 --- a/luni/src/main/java/libcore/net/http/HttpEngine.java +++ b/luni/src/main/java/libcore/net/http/HttpEngine.java @@ -69,10 +69,10 @@ import libcore.util.EmptyArray; * required, use {@link #automaticallyReleaseConnectionToPool()}. */ public class HttpEngine { - private static final CacheResponse BAD_GATEWAY_RESPONSE = new CacheResponse() { + private static final CacheResponse GATEWAY_TIMEOUT_RESPONSE = new CacheResponse() { @Override public Map<String, List<String>> getHeaders() throws IOException { Map<String, List<String>> result = new HashMap<String, List<String>>(); - result.put(null, Collections.singletonList("HTTP/1.1 502 Bad Gateway")); + result.put(null, Collections.singletonList("HTTP/1.1 504 Gateway Timeout")); return result; } @Override public InputStream getBody() throws IOException { @@ -223,14 +223,15 @@ public class HttpEngine { /* * The raw response source may require the network, but the request * headers may forbid network use. In that case, dispose of the network - * response and use a BAD_GATEWAY response instead. + * response and use a GATEWAY_TIMEOUT response instead, as specified + * by http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4. */ if (requestHeaders.isOnlyIfCached() && responseSource.requiresConnection()) { if (responseSource == ResponseSource.CONDITIONAL_CACHE) { IoUtils.closeQuietly(cachedResponseBody); } this.responseSource = ResponseSource.CACHE; - this.cacheResponse = BAD_GATEWAY_RESPONSE; + this.cacheResponse = GATEWAY_TIMEOUT_RESPONSE; RawHeaders rawResponseHeaders = RawHeaders.fromMultimap(cacheResponse.getHeaders()); setResponse(new ResponseHeaders(uri, rawResponseHeaders), cacheResponse.getBody()); } diff --git a/luni/src/test/java/libcore/net/http/HttpResponseCacheTest.java b/luni/src/test/java/libcore/net/http/HttpResponseCacheTest.java index 360ca44a48..133924e09f 100644 --- a/luni/src/test/java/libcore/net/http/HttpResponseCacheTest.java +++ b/luni/src/test/java/libcore/net/http/HttpResponseCacheTest.java @@ -959,7 +959,7 @@ public final class HttpResponseCacheTest extends TestCase { HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection(); connection.addRequestProperty("Cache-Control", "only-if-cached"); - assertBadGateway(connection); + assertGatewayTimeout(connection); } public void testRequestOnlyIfCachedWithFullResponseCached() throws IOException { @@ -983,7 +983,7 @@ public final class HttpResponseCacheTest extends TestCase { assertEquals("A", readAscii(server.getUrl("/").openConnection())); HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection(); connection.addRequestProperty("Cache-Control", "only-if-cached"); - assertBadGateway(connection); + assertGatewayTimeout(connection); } public void testRequestOnlyIfCachedWithUnhelpfulResponseCached() throws IOException { @@ -993,7 +993,7 @@ public final class HttpResponseCacheTest extends TestCase { assertEquals("A", readAscii(server.getUrl("/").openConnection())); HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection(); connection.addRequestProperty("Cache-Control", "only-if-cached"); - assertBadGateway(connection); + assertGatewayTimeout(connection); } public void testRequestCacheControlNoCache() throws Exception { @@ -1804,13 +1804,13 @@ public final class HttpResponseCacheTest extends TestCase { } } - private void assertBadGateway(HttpURLConnection connection) throws IOException { + private void assertGatewayTimeout(HttpURLConnection connection) throws IOException { try { connection.getInputStream(); fail(); } catch (FileNotFoundException expected) { } - assertEquals(HttpURLConnection.HTTP_BAD_GATEWAY, connection.getResponseCode()); + assertEquals(504, connection.getResponseCode()); assertEquals(-1, connection.getErrorStream().read()); } |
