1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package libcore.net.http; 18 19import java.util.Arrays; 20import junit.framework.TestCase; 21 22public class RawHeadersTest extends TestCase { 23 // http://code.google.com/p/android/issues/detail?id=6684 24 public void test_caseInsensitiveButCasePreserving() { 25 RawHeaders h = new RawHeaders(); 26 h.add("Content-Type", "text/plain"); 27 // Case-insensitive: 28 assertEquals("text/plain", h.get("Content-Type")); 29 assertEquals("text/plain", h.get("Content-type")); 30 assertEquals("text/plain", h.get("content-type")); 31 assertEquals("text/plain", h.get("CONTENT-TYPE")); 32 // ...but case-preserving: 33 assertEquals("Content-Type", h.toMultimap().keySet().toArray()[0]); 34 35 // We differ from the RI in that the Map we return is also case-insensitive. 36 // Our behavior seems more consistent. (And code that works on the RI will work on Android.) 37 assertEquals(Arrays.asList("text/plain"), h.toMultimap().get("Content-Type")); 38 assertEquals(Arrays.asList("text/plain"), h.toMultimap().get("Content-type")); // RI fails this. 39 } 40 41 // The copy constructor used to be broken for headers with multiple values. 42 // http://code.google.com/p/android/issues/detail?id=6722 43 public void test_copyConstructor() { 44 RawHeaders h1 = new RawHeaders(); 45 h1.add("key", "value1"); 46 h1.add("key", "value2"); 47 RawHeaders h2 = RawHeaders.fromMultimap(h1.toMultimap()); 48 assertEquals(2, h2.length()); 49 assertEquals("key", h2.getFieldName(0)); 50 assertEquals("value1", h2.getValue(0)); 51 assertEquals("key", h2.getFieldName(1)); 52 assertEquals("value2", h2.getValue(1)); 53 } 54} 55