Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/http/NoCache.java
41159 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
/*
25
* @test
26
* @bug 7133367
27
* @modules jdk.httpserver
28
* @library /test/lib
29
* @summary ResponseCache.put should not be called when setUseCaches(false)
30
*/
31
32
33
import java.net.*;
34
import java.io.IOException;
35
import java.util.List;
36
import java.util.Map;
37
import com.sun.net.httpserver.HttpExchange;
38
import com.sun.net.httpserver.HttpHandler;
39
import com.sun.net.httpserver.HttpServer;
40
import jdk.test.lib.net.URIBuilder;
41
42
public class NoCache
43
{
44
public static void main(String[] args) throws IOException {
45
ResponseCache.setDefault(new ThrowingCache());
46
47
HttpServer server = startHttpServer();
48
try {
49
URL url = URIBuilder.newBuilder()
50
.scheme("http")
51
.host(server.getAddress().getAddress())
52
.port(server.getAddress().getPort())
53
.path("/NoCache/")
54
.toURLUnchecked();
55
URLConnection uc = url.openConnection(Proxy.NO_PROXY);
56
uc.setUseCaches(false);
57
uc.getInputStream().close();
58
} finally {
59
server.stop(0);
60
// clear the system-wide cache handler, samevm/agentvm mode
61
ResponseCache.setDefault(null);
62
}
63
}
64
65
static class ThrowingCache extends ResponseCache {
66
@Override
67
public CacheResponse get(URI uri, String rqstMethod,
68
Map<String,List<String>> rqstHeaders) {
69
throw new RuntimeException("ResponseCache.get should not be called");
70
}
71
72
@Override
73
public CacheRequest put(URI uri, URLConnection conn) {
74
throw new RuntimeException("ResponseCache.put should not be called");
75
}
76
}
77
78
// HTTP Server
79
static HttpServer startHttpServer() throws IOException {
80
HttpServer httpServer = HttpServer.create(new InetSocketAddress(InetAddress.getLocalHost(), 0), 0);
81
httpServer.createContext("/NoCache/", new SimpleHandler());
82
httpServer.start();
83
return httpServer;
84
}
85
86
static class SimpleHandler implements HttpHandler {
87
@Override
88
public void handle(HttpExchange t) throws IOException {
89
t.sendResponseHeaders(200, -1);
90
t.close();
91
}
92
}
93
}
94
95