http-client-branch: review comment Add toString to HttpHeaders http-client-branch
authorchegar
Sat, 25 Nov 2017 16:23:20 +0000
branchhttp-client-branch
changeset 55873 b5e6a3201081
parent 55872 9c31615e8989
child 55874 ee17449ff241
http-client-branch: review comment Add toString to HttpHeaders
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpHeaders.java
test/jdk/java/net/httpclient/HeadersTest1.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpHeaders.java	Sat Nov 25 15:34:04 2017 +0300
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpHeaders.java	Sat Nov 25 16:23:20 2017 +0000
@@ -147,4 +147,18 @@
     public final int hashCode() {
         return map().hashCode();
     }
+
+    /**
+     * Returns the HTTP headers as a string.
+     *
+     * @return a string describing the HTTP headers
+     */
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(super.toString()).append(" ");
+        sb.append(map());
+        sb.append(" }");
+        return sb.toString();
+    }
 }
--- a/test/jdk/java/net/httpclient/HeadersTest1.java	Sat Nov 25 15:34:04 2017 +0300
+++ b/test/jdk/java/net/httpclient/HeadersTest1.java	Sat Nov 25 16:23:20 2017 +0000
@@ -95,16 +95,26 @@
             assertTrue(v1.isEmpty(), String.valueOf(v1));
             TestKit.assertUnmodifiableList(v1);
 
-            List<String> v2 = hd.allValues("X-Foo-Response");
-            assertNotNull(v2);
-            assertEquals(new HashSet<>(v2), Set.of("resp1", "resp2"));
-            TestKit.assertUnmodifiableList(v2);
+            // case insensitive
+            List<String> headernames = List.of("X-Foo-Response",
+                                               "x-foo-Response",
+                                               "x-fOo-REspoNse");
+            for (String headerName : headernames) {
+                List<String> v2 = hd.allValues(headerName);
+                assertNotNull(v2);
+                assertEquals(new HashSet<>(v2), Set.of("resp1", "resp2"));
+                TestKit.assertUnmodifiableList(v2);
+            }
 
             Map<String, List<String>> map = hd.map();
             TestKit.assertUnmodifiableMap(map);
             for (List<String> values : map.values()) {
                 TestKit.assertUnmodifiableList(values);
             }
+
+            // toString
+            hd.toString().toLowerCase().contains("content-length");
+            hd.toString().toLowerCase().contains("x-foo-response");
         } finally {
             server.stop(0);
             e.shutdownNow();