author | mikael |
Fri, 04 Dec 2015 15:08:49 -0800 | |
changeset 35090 | 1f5b6aa795d0 |
parent 18577 | f76979ce4bc4 |
child 38883 | d5de564f8089 |
permissions | -rw-r--r-- |
18577
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
1 |
/* |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
4 |
* |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
8 |
* |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
13 |
* accompanied this code). |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
14 |
* |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
18 |
* |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
21 |
* questions. |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
22 |
*/ |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
23 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
24 |
/* |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
25 |
* @test |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
26 |
* @bug 8015799 |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
27 |
* @summary HttpURLConnection.getHeaderFields() throws IllegalArgumentException |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
28 |
*/ |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
29 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
30 |
import com.sun.net.httpserver.*; |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
31 |
import java.io.IOException; |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
32 |
import java.io.OutputStream; |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
33 |
import java.net.*; |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
34 |
import java.util.*; |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
35 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
36 |
public class EmptyCookieHeader { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
37 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
38 |
public static void main(String[] args) throws Exception { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
39 |
new EmptyCookieHeader().runTest(); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
40 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
41 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
42 |
public void runTest() throws Exception { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
43 |
final CookieHandler oldHandler = CookieHandler.getDefault(); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
44 |
CookieHandler.setDefault(new TestCookieHandler()); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
45 |
HttpServer s = HttpServer.create(new InetSocketAddress(0), 0); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
46 |
try { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
47 |
startServer(s); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
48 |
URL url = new URL("http://localhost:" + s.getAddress().getPort() + "/"); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
49 |
HttpURLConnection c = (HttpURLConnection)url.openConnection(); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
50 |
c.getHeaderFields(); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
51 |
} finally { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
52 |
CookieHandler.setDefault(oldHandler); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
53 |
s.stop(0); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
54 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
55 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
56 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
57 |
static void startServer(HttpServer server) throws IOException { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
58 |
server.createContext("/", new EmptyCookieHandler()); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
59 |
server.start(); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
60 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
61 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
62 |
static class EmptyCookieHandler implements HttpHandler { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
63 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
64 |
@Override |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
65 |
public void handle(HttpExchange exchange) throws IOException { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
66 |
String requestMethod = exchange.getRequestMethod(); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
67 |
if (requestMethod.equalsIgnoreCase("GET")) { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
68 |
Headers responseHeaders = exchange.getResponseHeaders(); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
69 |
responseHeaders.set("Content-Type", "text/plain"); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
70 |
responseHeaders.set("Date", "June 13th 2012"); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
71 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
72 |
// No domain value set |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
73 |
responseHeaders.set("Set-Cookie2", "name=value"); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
74 |
responseHeaders.set("Set-Cookie2", ""); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
75 |
exchange.sendResponseHeaders(200, 0); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
76 |
try (OutputStream os = exchange.getResponseBody()) { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
77 |
String str = "This is what the server sent!"; |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
78 |
os.write(str.getBytes()); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
79 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
80 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
81 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
82 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
83 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
84 |
class TestCookieHandler extends CookieHandler { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
85 |
@Override |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
86 |
public Map<String,List<String>> get(URI uri, |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
87 |
Map<String,List<String>> respH) { |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
88 |
return new HashMap<>(); |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
89 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
90 |
|
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
91 |
@Override |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
92 |
public void put(URI uri, Map<String,List<String >> respH) { } |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
93 |
} |
f76979ce4bc4
8015799: HttpURLConnection.getHeaderFields() throws IllegalArgumentException
jzavgren
parents:
diff
changeset
|
94 |
} |