Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/net/httpserver/bugs/B6886436.java
41154 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
/**
25
* @test
26
* @bug 6886436
27
* @summary HttpServer should not send a body with 204 response.
28
* @library /test/lib
29
* @run main B6886436
30
* @run main/othervm -Djava.net.preferIPv6Addresses=true B6886436
31
*/
32
33
import com.sun.net.httpserver.*;
34
35
import java.util.*;
36
import java.util.concurrent.*;
37
import java.util.logging.*;
38
import java.io.*;
39
import java.net.*;
40
import jdk.test.lib.net.URIBuilder;
41
42
public class B6886436 {
43
44
public static void main (String[] args) throws Exception {
45
Logger logger = Logger.getLogger ("com.sun.net.httpserver");
46
ConsoleHandler c = new ConsoleHandler();
47
c.setLevel (Level.WARNING);
48
logger.addHandler (c);
49
logger.setLevel (Level.WARNING);
50
Handler handler = new Handler();
51
InetAddress loopback = InetAddress.getLoopbackAddress();
52
InetSocketAddress addr = new InetSocketAddress (loopback, 0);
53
HttpServer server = HttpServer.create (addr, 0);
54
HttpContext ctx = server.createContext ("/test", handler);
55
ExecutorService executor = Executors.newCachedThreadPool();
56
server.setExecutor (executor);
57
server.start ();
58
59
URL url = URIBuilder.newBuilder()
60
.scheme("http")
61
.loopback()
62
.port(server.getAddress().getPort())
63
.path("/test/foo.html")
64
.toURL();
65
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
66
try {
67
InputStream is = urlc.getInputStream();
68
while (is.read()!= -1) ;
69
is.close ();
70
urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
71
urlc.setReadTimeout (3000);
72
is = urlc.getInputStream();
73
while (is.read()!= -1);
74
is.close ();
75
76
} catch (IOException e) {
77
server.stop(2);
78
executor.shutdown();
79
throw new RuntimeException ("Test failed");
80
}
81
server.stop(2);
82
executor.shutdown();
83
System.out.println ("OK");
84
}
85
86
public static boolean error = false;
87
88
static class Handler implements HttpHandler {
89
int invocation = 1;
90
public void handle (HttpExchange t)
91
throws IOException
92
{
93
InputStream is = t.getRequestBody();
94
Headers map = t.getRequestHeaders();
95
Headers rmap = t.getResponseHeaders();
96
while (is.read () != -1) ;
97
is.close();
98
// send a 204 response with an empty chunked body
99
t.sendResponseHeaders (204, 0);
100
t.close();
101
}
102
}
103
}
104
105