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