Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 83935 invoked from network); 21 Feb 2010 14:02:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Feb 2010 14:02:10 -0000 Received: (qmail 95792 invoked by uid 500); 21 Feb 2010 14:02:10 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 95730 invoked by uid 500); 21 Feb 2010 14:02:10 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 95721 invoked by uid 99); 21 Feb 2010 14:02:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Feb 2010 14:02:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Feb 2010 14:02:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B23F023889BB; Sun, 21 Feb 2010 14:01:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r912351 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java Date: Sun, 21 Feb 2010 14:01:46 -0000 To: commits@harmony.apache.org From: hindessm@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100221140146.B23F023889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hindessm Date: Sun Feb 21 14:01:46 2010 New Revision: 912351 URL: http://svn.apache.org/viewvc?rev=912351&view=rev Log: Add regression tests and fix remaining issues from "[#HARMONY-6452] HttpUrlConnection converts request headers to lowercase ...". Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java?rev=912351&r1=912350&r2=912351&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java Sun Feb 21 14:01:46 2010 @@ -19,6 +19,8 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -31,12 +33,12 @@ */ public class Header implements Cloneable { /* - * we use the non-synchronized ArrayList and HashMap instead of the + * we use the non-synchronized ArrayList and TreehMap instead of the * synchronized Vector and Hashtable */ private ArrayList props; - private HashMap> keyTable; + private SortedMap> keyTable; private String statusLine; @@ -48,7 +50,8 @@ public Header() { super(); this.props = new ArrayList(20); - this.keyTable = new HashMap>(20); + this.keyTable = new TreeMap>( + String.CASE_INSENSITIVE_ORDER); } /** @@ -79,7 +82,8 @@ try { Header clone = (Header) super.clone(); clone.props = (ArrayList) props.clone(); - clone.keyTable = new HashMap>(20); + clone.keyTable = new TreeMap>( + String.CASE_INSENSITIVE_ORDER); for (Map.Entry> next : this.keyTable .entrySet()) { LinkedList v = (LinkedList) next.getValue() @@ -105,7 +109,7 @@ LinkedList list = keyTable.get(key); if (list == null) { list = new LinkedList(); - keyTable.put(key.toLowerCase(), list); + keyTable.put(key, list); } list.add(value); props.add(key); @@ -197,7 +201,7 @@ * such key exists. */ public String get(String key) { - LinkedList result = keyTable.get(key.toLowerCase()); + LinkedList result = keyTable.get(key); if (result == null) { return null; } Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java?rev=912351&r1=912350&r2=912351&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java Sun Feb 21 14:01:46 2010 @@ -141,6 +141,105 @@ } /** + * Regression test for HARMONY-6452 + */ + public void test_RequestProperty_case_insensitivity() + throws MalformedURLException, IOException { + + URLConnection u = + (URLConnection)(new URL("http://example.org/").openConnection()); + u.setRequestProperty("KEY", "upper"); + u.setRequestProperty("key", "lower"); + assertEquals("set for \"KEY\" is overwritten by set for \"key\"", + "lower", u.getRequestProperty("KEY")); + assertEquals("value can be retrieved by either key case", + "lower", u.getRequestProperty("key")); + assertEquals("value can be retrieved by arbitrary key case", + "lower", u.getRequestProperty("kEy")); + + Map> props = u.getRequestProperties(); + List values = props.get("KEY"); + assertNotNull("first key does have an entry", values); + assertNull("second key does not have an entry", props.get("key")); + + assertEquals("returned value list is correct size", 1, values.size()); + assertTrue("returned value list contains expected value", + values.contains("lower")); + + + // repeat the above with the case of keys reversed to confirm + // that first key is significant one + u = (URLConnection)(new URL("http://example.org/").openConnection()); + u.setRequestProperty("key", "lower"); + u.setRequestProperty("KEY", "upper"); + assertEquals("set for \"key\" is overwritten by set for \"KEY\"", + "upper", u.getRequestProperty("KEY")); + assertEquals("value can be retrieved by either key case", + "upper", u.getRequestProperty("key")); + assertEquals("value can be retrieved by arbitrary key case", + "upper", u.getRequestProperty("kEy")); + + props = u.getRequestProperties(); + values = props.get("key"); + assertNotNull("first key does have an entry", values); + assertNull("second key does not have an entry", props.get("KEY")); + + assertEquals("returned value list is correct size", 1, values.size()); + assertTrue("returned value list contains expected value", + values.contains("upper")); + + + // repeat the first test with set and add methods + u = (URLConnection)(new URL("http://example.org/").openConnection()); + u.setRequestProperty("KEY", "value1"); + u.addRequestProperty("key", "value2"); + assertEquals("value for \"KEY\" is the last one added", + "value2", u.getRequestProperty("KEY")); + assertEquals("value can be retrieved by either key case", + "value2", u.getRequestProperty("key")); + assertEquals("value can be retrieved by arbitrary key case", + "value2", u.getRequestProperty("kEy")); + + props = u.getRequestProperties(); + values = props.get("KEY"); + assertNotNull("first key does have an entry", values); + assertNull("second key does not have an entry", props.get("key")); + + assertEquals("returned value list is correct size", 2, values.size()); + assertTrue("returned value list contains first value", + values.contains("value1")); + assertTrue("returned value list contains second value", + values.contains("value2")); + + + // repeat the previous test with only add methods + u = (URLConnection)(new URL("http://example.org/").openConnection()); + u.addRequestProperty("KEY", "value1"); + u.addRequestProperty("key", "value2"); + u.addRequestProperty("Key", "value3"); + assertEquals("value for \"KEY\" is the last one added", + "value3", u.getRequestProperty("KEY")); + assertEquals("value can be retrieved by another key case", + "value3", u.getRequestProperty("key")); + assertEquals("value can be retrieved by arbitrary key case", + "value3", u.getRequestProperty("kEy")); + + props = u.getRequestProperties(); + values = props.get("KEY"); + assertNotNull("first key does have an entry", values); + assertNull("second key does not have an entry", props.get("key")); + assertNull("third key does not have an entry", props.get("Key")); + + assertEquals("returned value list is correct size", 3, values.size()); + assertTrue("returned value list contains first value", + values.contains("value1")); + assertTrue("returned value list contains second value", + values.contains("value2")); + assertTrue("returned value list contains second value", + values.contains("value3")); + } + + /** * @tests java.net.URLConnection#addRequestProperty(java.lang.String,java.lang.String) */ public void test_addRequestPropertyLjava_lang_StringLjava_lang_String()