Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/ResponseCache/B6181108.java
41152 views
1
/*
2
* Copyright (c) 2004, 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
/**
25
* @test
26
* @bug 6181108
27
* @library /test/lib
28
* @summary double encoded URL passed to ResponseCache
29
* @author Edward Wang
30
*/
31
32
import java.net.*;
33
import java.util.*;
34
import java.io.*;
35
import jdk.test.lib.net.URIBuilder;
36
import static java.net.Proxy.NO_PROXY;
37
38
public class B6181108 implements Runnable {
39
ServerSocket ss;
40
static String urlWithSpace;
41
42
/*
43
* "Our" http server just return 200
44
*/
45
public void run() {
46
try {
47
Socket s = ss.accept();
48
49
InputStream is = s.getInputStream();
50
BufferedReader r = new BufferedReader(new InputStreamReader(is));
51
String x;
52
while ((x=r.readLine()) != null) {
53
if (x.length() ==0) {
54
break;
55
}
56
}
57
PrintStream out = new PrintStream(
58
new BufferedOutputStream(
59
s.getOutputStream() ));
60
61
/* response 200 */
62
out.print("HTTP/1.1 200 OK\r\n");
63
out.print("Content-Type: text/html; charset=iso-8859-1\r\n");
64
out.print("Content-Length: 0\r\n");
65
out.print("Connection: close\r\n");
66
out.print("\r\n");
67
out.print("\r\n");
68
69
out.flush();
70
71
s.close();
72
} catch (Exception e) {
73
e.printStackTrace();
74
} finally {
75
try { ss.close(); } catch (IOException unused) {}
76
}
77
}
78
79
static class ResponseCache extends java.net.ResponseCache {
80
public CacheResponse get(URI uri, String method, Map<String,List<String>> hdrs) {
81
System.out.println("get uri = " + uri);
82
if (!urlWithSpace.equals(uri.toString())) {
83
throw new RuntimeException("test failed");
84
}
85
return null;
86
}
87
public CacheRequest put(URI uri, URLConnection urlc) {
88
System.out.println("put uri = " + uri);
89
return null;
90
}
91
}
92
93
B6181108() throws Exception {
94
/* start the server */
95
InetAddress loopback = InetAddress.getLoopbackAddress();
96
ss = new ServerSocket();
97
ss.bind(new InetSocketAddress(loopback, 0));
98
(new Thread(this)).start();
99
100
ResponseCache.setDefault(new ResponseCache());
101
String base = URIBuilder.newBuilder()
102
.scheme("http")
103
.loopback()
104
.port(ss.getLocalPort())
105
.build()
106
.toString();
107
urlWithSpace = base + "/space%20test/page1.html";
108
URL url = new URL(urlWithSpace);
109
URLConnection urlc = url.openConnection(NO_PROXY);
110
int i = ((HttpURLConnection)(urlc)).getResponseCode();
111
System.out.println("response code = " + i);
112
ResponseCache.setDefault(null);
113
}
114
115
public static void main(String args[]) throws Exception {
116
new B6181108();
117
}
118
119
}
120
121