Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/http/B6890349.java
41159 views
1
/*
2
* Copyright (c) 2009, 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 6890349
26
* @library /test/lib
27
* @run main/othervm B6890349
28
* @run main/othervm -Djava.net.preferIPv6Addresses=true B6890349
29
* @summary Light weight HTTP server
30
*/
31
32
import java.net.*;
33
import java.io.*;
34
35
public class B6890349 extends Thread {
36
public static final void main(String[] args) throws Exception {
37
38
try {
39
ServerSocket server = new ServerSocket();
40
InetAddress loopback = InetAddress.getLoopbackAddress();
41
InetSocketAddress address = new InetSocketAddress(loopback, 0);
42
server.bind(address);
43
44
int port = server.getLocalPort();
45
System.out.println ("listening on " + port);
46
B6890349 t = new B6890349 (server);
47
t.start();
48
URL u = new URL("http",
49
InetAddress.getLoopbackAddress().getHostAddress(),
50
port,
51
"/foo\nbar");
52
System.out.println("URL: " + u);
53
HttpURLConnection urlc = (HttpURLConnection)u.openConnection(Proxy.NO_PROXY);
54
InputStream is = urlc.getInputStream();
55
throw new RuntimeException ("Test failed");
56
} catch (IOException e) {
57
System.out.println ("Caught expected exception: " + e);
58
}
59
}
60
61
ServerSocket server;
62
63
B6890349 (ServerSocket server) {
64
this.server = server;
65
}
66
67
String resp = "HTTP/1.1 200 Ok\r\nContent-length: 0\r\n\r\n";
68
69
public void run () {
70
try {
71
Socket s = server.accept ();
72
OutputStream os = s.getOutputStream();
73
os.write (resp.getBytes());
74
} catch (IOException e) {
75
System.out.println (e);
76
}
77
}
78
}
79
80