Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/http/Modified.java
41159 views
1
/*
2
* Copyright (c) 1998, 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 4092605
27
* @library /test/lib
28
* @run main/othervm Modified
29
* @run main/othervm -Djava.net.preferIPv6Addresses=true Modified
30
* @summary Test HttpURLConnection setIfModifiedSince
31
*
32
*/
33
34
import java.net.*;
35
import java.io.*;
36
import jdk.test.lib.net.URIBuilder;
37
38
public class Modified implements Runnable {
39
40
ServerSocket ss;
41
42
public void run() {
43
try {
44
Socket s = ss.accept();
45
boolean gotIfModified = false;
46
47
BufferedReader in = new BufferedReader(
48
new InputStreamReader(s.getInputStream()) );
49
50
String str = null;
51
do {
52
str = in.readLine();
53
if (str.startsWith("If-Modified-Since")) {
54
gotIfModified = true;
55
}
56
if (str.equals("")) {
57
break;
58
}
59
} while (str != null);
60
61
PrintStream out = new PrintStream(
62
new BufferedOutputStream(
63
s.getOutputStream() ));
64
65
if (gotIfModified) {
66
out.print("HTTP/1.1 304 Not Modified\r\n");
67
} else {
68
out.print("HTTP/1.1 200 OK\r\n");
69
}
70
71
out.print("Content-Type: text/html\r\n");
72
out.print("Connection: close\r\n");
73
out.print("\r\n");
74
out.flush();
75
76
s.close();
77
78
} catch (Exception e) {
79
e.printStackTrace();
80
}
81
}
82
83
Modified() throws Exception {
84
85
InetAddress loopback = InetAddress.getLoopbackAddress();
86
InetSocketAddress address = new InetSocketAddress(loopback, 0);
87
ss = new ServerSocket();
88
ss.bind(address);
89
int port = ss.getLocalPort();
90
91
Thread thr = new Thread(this);
92
thr.start();
93
94
URL testURL = URIBuilder.newBuilder()
95
.scheme("http")
96
.host(loopback)
97
.port(port)
98
.path("/index.html")
99
.toURL();
100
URLConnection URLConn = testURL.openConnection(Proxy.NO_PROXY);
101
HttpURLConnection httpConn;
102
103
if (URLConn instanceof HttpURLConnection) {
104
httpConn = (HttpURLConnection)URLConn;
105
httpConn.setAllowUserInteraction(false);
106
httpConn.setIfModifiedSince(9990000000000L);
107
int response = httpConn.getResponseCode();
108
if (response != 304)
109
throw new RuntimeException("setModifiedSince failure.");
110
}
111
}
112
113
public static void main(String args[]) throws Exception {
114
new Modified();
115
}
116
}
117
118