Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/HttpCookie/IllegalCookieNameTest.java
41152 views
1
/*
2
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 7183292
26
* @library /test/lib
27
* @modules jdk.httpserver
28
* @run main IllegalCookieNameTest
29
* @run main/othervm -Djava.net.preferIPv6Addresses=true IllegalCookieNameTest
30
*/
31
import java.net.*;
32
import java.util.*;
33
import java.io.*;
34
import com.sun.net.httpserver.*;
35
import jdk.test.lib.net.URIBuilder;
36
37
public class IllegalCookieNameTest {
38
public static void main(String[] args) throws Exception {
39
HttpServer s = null;
40
try {
41
InetAddress loopback = InetAddress.getLoopbackAddress();
42
InetSocketAddress addr = new InetSocketAddress(loopback, 0);
43
s = HttpServer.create(addr, 10);
44
s.createContext("/", new HHandler());
45
s.start();
46
String u = URIBuilder.newBuilder()
47
.scheme("http")
48
.loopback()
49
.port(s.getAddress().getPort())
50
.path("/")
51
.build().toString();
52
CookieHandler.setDefault(new TestCookieHandler());
53
URL url = new URL(u);
54
HttpURLConnection c = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
55
c.getHeaderFields();
56
System.out.println ("OK");
57
} finally {
58
s.stop(1);
59
}
60
}
61
}
62
63
class TestCookieHandler extends CookieHandler {
64
@Override
65
public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
66
return new HashMap<String, List<String>>();
67
}
68
69
@Override
70
public void put(URI uri, Map<String, List<String>> responseHeaders) {
71
}
72
}
73
74
class HHandler implements HttpHandler {
75
public void handle (HttpExchange e) {
76
try {
77
Headers h = e.getResponseHeaders();
78
h.set ("Set-Cookie", "domain=; expires=Mon, 01-Jan-1990 00:00:00 GMT; path=/; domain=.foo.com");
79
e.sendResponseHeaders(200, -1);
80
e.close();
81
} catch (Exception ex) {
82
System.out.println (ex);
83
}
84
}
85
}
86
87