am f2c696cb: am b87331c8: Merge "HTTP headers are case insensitive per RFC 2616 §4.2 "Message Headers""

* commit 'f2c696cba2a2077dbfc5ccbb3a4215257b33bd57':
  HTTP headers are case insensitive per RFC 2616 §4.2 "Message Headers"
diff --git a/src/com/android/volley/toolbox/BasicNetwork.java b/src/com/android/volley/toolbox/BasicNetwork.java
index 42696e2..c76ef6a 100644
--- a/src/com/android/volley/toolbox/BasicNetwork.java
+++ b/src/com/android/volley/toolbox/BasicNetwork.java
@@ -44,9 +44,11 @@
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.SocketTimeoutException;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.TreeMap;
 
 /**
  * A network performing Volley requests over an {@link HttpStack}.
@@ -86,7 +88,7 @@
         while (true) {
             HttpResponse httpResponse = null;
             byte[] responseContents = null;
-            Map<String, String> responseHeaders = new HashMap<String, String>();
+            Map<String, String> responseHeaders = Collections.emptyMap();
             try {
                 // Gather headers.
                 Map<String, String> headers = new HashMap<String, String>();
@@ -251,8 +253,8 @@
     /**
      * Converts Headers[] to Map<String, String>.
      */
-    private static Map<String, String> convertHeaders(Header[] headers) {
-        Map<String, String> result = new HashMap<String, String>();
+    protected static Map<String, String> convertHeaders(Header[] headers) {
+        Map<String, String> result = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
         for (int i = 0; i < headers.length; i++) {
             result.put(headers[i].getName(), headers[i].getValue());
         }
diff --git a/tests/src/com/android/volley/toolbox/HttpHeaderParserTest.java b/tests/src/com/android/volley/toolbox/HttpHeaderParserTest.java
index 547cc85..8f703f0 100644
--- a/tests/src/com/android/volley/toolbox/HttpHeaderParserTest.java
+++ b/tests/src/com/android/volley/toolbox/HttpHeaderParserTest.java
@@ -23,6 +23,9 @@
 
 import junit.framework.TestCase;
 
+import org.apache.http.Header;
+import org.apache.http.message.BasicHeader;
+
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -198,4 +201,26 @@
         headers.put("Content-Type", "text/plain;");
         assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
     }
+
+    public void testParseCaseInsensitive() {
+
+        long now = System.currentTimeMillis();
+
+        Header[] headersArray = new Header[5];
+        headersArray[0] = new BasicHeader("eTAG", "Yow!");
+        headersArray[1] = new BasicHeader("DATE", rfc1123Date(now));
+        headersArray[2] = new BasicHeader("expires", rfc1123Date(now + ONE_HOUR_MILLIS));
+        headersArray[3] = new BasicHeader("cache-control", "public, max-age=86400");
+        headersArray[4] = new BasicHeader("content-type", "text/plain");
+
+        Map<String, String> headers = BasicNetwork.convertHeaders(headersArray);
+        NetworkResponse response = new NetworkResponse(0, null, headers, false);
+        Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
+
+        assertNotNull(entry);
+        assertEquals("Yow!", entry.etag);
+        assertEqualsWithin(now + 24 * ONE_HOUR_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
+        assertEquals(entry.softTtl, entry.ttl);
+        assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
+    }
 }