Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/URLConnection/HttpContinueStackOverflow.java
38811 views
1
/*
2
* Copyright (c) 2000, 2010, 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 4258697
26
* @summary Make sure that http CONTINUE status followed by invalid
27
* response doesn't cause HttpClient to recursively loop and
28
* eventually StackOverflow.
29
*
30
*/
31
import java.io.BufferedReader;
32
import java.io.InputStreamReader;
33
import java.io.IOException;
34
import java.io.PrintStream;
35
import java.net.ServerSocket;
36
import java.net.Socket;
37
import java.net.URL;
38
import java.net.HttpURLConnection;
39
40
public class HttpContinueStackOverflow {
41
42
static class Server implements Runnable {
43
int port;
44
ServerSocket serverSock ;
45
46
Server() throws IOException {
47
serverSock = new ServerSocket(0);
48
}
49
50
int getLocalPort() {
51
return serverSock.getLocalPort();
52
}
53
54
public void run() {
55
Socket sock = null;
56
try {
57
serverSock.setSoTimeout(10000);
58
sock = serverSock.accept();
59
60
/* setup streams and read http request */
61
BufferedReader in = new BufferedReader(
62
new InputStreamReader(sock.getInputStream()));
63
PrintStream out = new PrintStream( sock.getOutputStream() );
64
in.readLine();
65
66
/* send continue followed by invalid response */
67
out.println("HTTP/1.1 100 Continue\r");
68
out.println("\r");
69
out.println("junk junk junk");
70
out.flush();
71
} catch (Exception e) {
72
e.printStackTrace();
73
} finally {
74
try { serverSock.close(); } catch (IOException unused) {}
75
try { sock.close(); } catch (IOException unused) {}
76
}
77
}
78
}
79
80
HttpContinueStackOverflow() throws Exception {
81
/* create the server */
82
Server s = new Server();
83
(new Thread(s)).start();
84
85
/* connect to server, connect to server and get response code */
86
URL url = new URL("http", "localhost", s.getLocalPort(), "anything.html");
87
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
88
conn.getResponseCode();
89
System.out.println("TEST PASSED");
90
}
91
92
public static void main(String args[]) throws Exception {
93
System.out.println("Testing 100-Continue");
94
new HttpContinueStackOverflow();
95
}
96
}
97
98