1 /* |
1 /* |
2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 8015799 |
26 * @bug 8015799 |
27 * @modules jdk.httpserver |
27 * @modules jdk.httpserver |
28 * @summary HttpURLConnection.getHeaderFields() throws IllegalArgumentException |
28 * @summary HttpURLConnection.getHeaderFields() throws IllegalArgumentException |
|
29 * @library /test/lib |
|
30 * @run main EmptyCookieHeader |
|
31 * @run main/othervm -Djava.net.preferIPv6Addresses=true EmptyCookieHeader |
29 */ |
32 */ |
30 |
33 |
31 import com.sun.net.httpserver.*; |
34 import com.sun.net.httpserver.*; |
32 import java.io.IOException; |
35 import java.io.IOException; |
33 import java.io.OutputStream; |
36 import java.io.OutputStream; |
34 import java.net.*; |
37 import java.net.*; |
35 import java.util.*; |
38 import java.util.*; |
|
39 import jdk.test.lib.net.URIBuilder; |
36 |
40 |
37 public class EmptyCookieHeader { |
41 public class EmptyCookieHeader { |
38 |
42 |
39 public static void main(String[] args) throws Exception { |
43 public static void main(String[] args) throws Exception { |
40 new EmptyCookieHeader().runTest(); |
44 new EmptyCookieHeader().runTest(); |
41 } |
45 } |
42 |
46 |
43 public void runTest() throws Exception { |
47 public void runTest() throws Exception { |
44 final CookieHandler oldHandler = CookieHandler.getDefault(); |
48 final CookieHandler oldHandler = CookieHandler.getDefault(); |
45 CookieHandler.setDefault(new TestCookieHandler()); |
49 CookieHandler.setDefault(new TestCookieHandler()); |
46 HttpServer s = HttpServer.create(new InetSocketAddress(0), 0); |
50 InetAddress loopback = InetAddress.getLoopbackAddress(); |
|
51 HttpServer s = HttpServer.create(new InetSocketAddress(loopback, 0), 0); |
47 try { |
52 try { |
48 startServer(s); |
53 startServer(s); |
49 URL url = new URL("http://localhost:" + s.getAddress().getPort() + "/"); |
54 URL url = URIBuilder.newBuilder() |
50 HttpURLConnection c = (HttpURLConnection)url.openConnection(); |
55 .scheme("http") |
|
56 .loopback() |
|
57 .port(s.getAddress().getPort()) |
|
58 .path("/") |
|
59 .toURL(); |
|
60 HttpURLConnection c = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY); |
51 c.getHeaderFields(); |
61 c.getHeaderFields(); |
52 } finally { |
62 } finally { |
53 CookieHandler.setDefault(oldHandler); |
63 CookieHandler.setDefault(oldHandler); |
54 s.stop(0); |
64 s.stop(0); |
55 } |
65 } |