26 import java.io.ByteArrayInputStream; |
26 import java.io.ByteArrayInputStream; |
27 import java.net.ProtocolException; |
27 import java.net.ProtocolException; |
28 import java.nio.ByteBuffer; |
28 import java.nio.ByteBuffer; |
29 import java.util.ArrayList; |
29 import java.util.ArrayList; |
30 import java.util.Arrays; |
30 import java.util.Arrays; |
|
31 import java.util.Collections; |
31 import java.util.HashMap; |
32 import java.util.HashMap; |
32 import java.util.List; |
33 import java.util.List; |
33 import java.util.Map; |
34 import java.util.Map; |
34 import java.util.stream.IntStream; |
35 import java.util.stream.IntStream; |
35 import sun.net.www.MessageHeader; |
36 import sun.net.www.MessageHeader; |
115 "X-Foo:\r\n" + // no value, same header appears multiple times |
116 "X-Foo:\r\n" + // no value, same header appears multiple times |
116 "X-Foo: dfuchs\r\n" + |
117 "X-Foo: dfuchs\r\n" + |
117 "Content-Length: 0\r\n" + |
118 "Content-Length: 0\r\n" + |
118 "X-Foo: michaelm\r\n" + |
119 "X-Foo: michaelm\r\n" + |
119 "X-Foo: prappo\r\n\r\n", |
120 "X-Foo: prappo\r\n\r\n", |
|
121 |
|
122 "HTTP/1.1 200 OK\r\n" + |
|
123 "Accept-Ranges: bytes\r\n" + |
|
124 "Cache-control: max-age=0, no-cache=\"set-cookie\"\r\n" + |
|
125 "Content-Length: 132868\r\n" + |
|
126 "Content-Type: text/html; charset=UTF-8\r\n" + |
|
127 "Date: Sun, 05 Nov 2017 22:24:03 GMT\r\n" + |
|
128 "Server: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips Communique/4.2.2\r\n" + |
|
129 "Set-Cookie: AWSELB=AF7927F5100F4202119876ED2436B5005EE;PATH=/;MAX-AGE=900\r\n" + |
|
130 "Vary: Host,Accept-Encoding,User-Agent\r\n" + |
|
131 "X-Mod-Pagespeed: 1.12.34.2-0\r\n" + |
|
132 "Connection: keep-alive\r\n\r\n" |
120 }; |
133 }; |
121 Arrays.stream(basic).forEach(responses::add); |
134 Arrays.stream(basic).forEach(responses::add); |
122 |
135 |
123 String[] foldingTemplate = |
136 String[] foldingTemplate = |
124 { "HTTP/1.1 200 OK\r\n" + |
137 { "HTTP/1.1 200 OK\r\n" + |
301 |
314 |
302 if (expected.equals(actual)) |
315 if (expected.equals(actual)) |
303 return; |
316 return; |
304 |
317 |
305 assertEquals(expected.size(), actual.size(), |
318 assertEquals(expected.size(), actual.size(), |
306 format("%s. Expected size %d, actual size %s. expected= %s, actual=%s.", |
319 format("%s. Expected size %d, actual size %s. %nexpected= %s,%n actual=%s.", |
307 msg, expected.size(), actual.size(), expected, actual)); |
320 msg, expected.size(), actual.size(), mapToString(expected), mapToString(actual))); |
308 |
321 |
309 for (Map.Entry<String,List<String>> e : expected.entrySet()) { |
322 for (Map.Entry<String,List<String>> e : expected.entrySet()) { |
310 String key = e.getKey(); |
323 String key = e.getKey(); |
311 List<String> values = e.getValue(); |
324 List<String> values = e.getValue(); |
312 |
325 |
325 } |
338 } |
326 assertTrue(found, format("header name, %s, not found in %s", key, actual)); |
339 assertTrue(found, format("header name, %s, not found in %s", key, actual)); |
327 } |
340 } |
328 } |
341 } |
329 |
342 |
|
343 static String mapToString(Map<String,List<String>> map) { |
|
344 StringBuilder sb = new StringBuilder(); |
|
345 List<String> sortedKeys = new ArrayList(map.keySet()); |
|
346 Collections.sort(sortedKeys); |
|
347 for (String key : sortedKeys) { |
|
348 List<String> values = map.get(key); |
|
349 sb.append("\n\t" + key + " | " + values); |
|
350 } |
|
351 return sb.toString(); |
|
352 } |
|
353 |
330 // --- |
354 // --- |
331 |
355 |
332 /* Main entry point for standalone testing of the main functional test. */ |
356 /* Main entry point for standalone testing of the main functional test. */ |
333 public static void main(String... args) throws Exception { |
357 public static void main(String... args) throws Exception { |
334 Http1HeaderParserTest test = new Http1HeaderParserTest(); |
358 Http1HeaderParserTest test = new Http1HeaderParserTest(); |