author | chegar |
Wed, 21 Jul 2010 13:29:26 +0100 | |
changeset 6115 | 7c523cf2bc8a |
parent 5506 | 202f599c92aa |
child 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 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; |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
33 |
import java.io.IOException; |
2 | 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; |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
44 |
ServerSocket serverSock ; |
2 | 45 |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
46 |
Server() throws IOException { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
47 |
serverSock = new ServerSocket(0); |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
48 |
} |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
49 |
|
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
50 |
int getLocalPort() { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
51 |
return serverSock.getLocalPort(); |
2 | 52 |
} |
53 |
||
54 |
public void run() { |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
55 |
Socket sock = null; |
2 | 56 |
try { |
57 |
serverSock.setSoTimeout(10000); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
58 |
sock = serverSock.accept(); |
2 | 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() ); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
64 |
in.readLine(); |
2 | 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(); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
73 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
74 |
try { serverSock.close(); } catch (IOException unused) {} |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
75 |
try { sock.close(); } catch (IOException unused) {} |
2 | 76 |
} |
77 |
} |
|
78 |
} |
|
79 |
||
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
80 |
HttpContinueStackOverflow() throws Exception { |
2 | 81 |
/* create the server */ |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
82 |
Server s = new Server(); |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
83 |
(new Thread(s)).start(); |
2 | 84 |
|
85 |
/* connect to server, connect to server and get response code */ |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
86 |
URL url = new URL("http", "localhost", s.getLocalPort(), "anything.html"); |
2 | 87 |
HttpURLConnection conn = (HttpURLConnection)url.openConnection(); |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
88 |
conn.getResponseCode(); |
2 | 89 |
System.out.println("TEST PASSED"); |
90 |
} |
|
91 |
||
92 |
public static void main(String args[]) throws Exception { |
|
93 |
System.out.println("Testing 100-Continue"); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
94 |
new HttpContinueStackOverflow(); |
2 | 95 |
} |
96 |
} |