提交 1e39ea35 编写于 作者: I igerasim

8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming

Reviewed-by: michaelm
上级 68ed55d6
...@@ -657,9 +657,10 @@ public class HttpClient extends NetworkClient { ...@@ -657,9 +657,10 @@ public class HttpClient extends NetworkClient {
cachedHttpClient = false; cachedHttpClient = false;
if (!failedOnce && requests != null) { if (!failedOnce && requests != null) {
failedOnce = true; failedOnce = true;
if (getRequestMethod().equals("CONNECT") || if (getRequestMethod().equals("CONNECT")
(httpuc.getRequestMethod().equals("POST") && || streaming
(!retryPostProp || streaming))) { || (httpuc.getRequestMethod().equals("POST")
&& !retryPostProp)) {
// do not retry the request // do not retry the request
} else { } else {
// try once more // try once more
...@@ -769,9 +770,10 @@ public class HttpClient extends NetworkClient { ...@@ -769,9 +770,10 @@ public class HttpClient extends NetworkClient {
} else if (nread != 8) { } else if (nread != 8) {
if (!failedOnce && requests != null) { if (!failedOnce && requests != null) {
failedOnce = true; failedOnce = true;
if (getRequestMethod().equals("CONNECT") || if (getRequestMethod().equals("CONNECT")
(httpuc.getRequestMethod().equals("POST") && || streaming
(!retryPostProp || streaming))) { || (httpuc.getRequestMethod().equals("POST")
&& !retryPostProp)) {
// do not retry the request // do not retry the request
} else { } else {
closeServer(); closeServer();
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
/* /*
* @test * @test
* @bug 6672144 * @bug 6672144 8050983
* @summary HttpURLConnection.getInputStream sends POST request after failed chunked send * @summary Do not retry failed request with a streaming body.
*/ */
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
...@@ -33,6 +33,7 @@ import java.net.URL; ...@@ -33,6 +33,7 @@ import java.net.URL;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import static java.lang.System.out;
public class StreamingRetry implements Runnable { public class StreamingRetry implements Runnable {
static final int ACCEPT_TIMEOUT = 20 * 1000; // 20 seconds static final int ACCEPT_TIMEOUT = 20 * 1000; // 20 seconds
...@@ -43,11 +44,17 @@ public class StreamingRetry implements Runnable { ...@@ -43,11 +44,17 @@ public class StreamingRetry implements Runnable {
} }
void instanceMain() throws IOException { void instanceMain() throws IOException {
test(); out.println("Test with default method");
test(null);
out.println("Test with POST method");
test("POST");
out.println("Test with PUT method");
test("PUT");
if (failed > 0) throw new RuntimeException("Some tests failed"); if (failed > 0) throw new RuntimeException("Some tests failed");
} }
void test() throws IOException { void test(String method) throws IOException {
ss = new ServerSocket(0); ss = new ServerSocket(0);
ss.setSoTimeout(ACCEPT_TIMEOUT); ss.setSoTimeout(ACCEPT_TIMEOUT);
int port = ss.getLocalPort(); int port = ss.getLocalPort();
...@@ -58,6 +65,8 @@ public class StreamingRetry implements Runnable { ...@@ -58,6 +65,8 @@ public class StreamingRetry implements Runnable {
URL url = new URL("http://localhost:" + port + "/"); URL url = new URL("http://localhost:" + port + "/");
HttpURLConnection uc = (HttpURLConnection) url.openConnection(); HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setDoOutput(true); uc.setDoOutput(true);
if (method != null)
uc.setRequestMethod(method);
uc.setChunkedStreamingMode(4096); uc.setChunkedStreamingMode(4096);
OutputStream os = uc.getOutputStream(); OutputStream os = uc.getOutputStream();
os.write("Hello there".getBytes()); os.write("Hello there".getBytes());
...@@ -79,7 +88,7 @@ public class StreamingRetry implements Runnable { ...@@ -79,7 +88,7 @@ public class StreamingRetry implements Runnable {
ss.close(); ss.close();
fail("The server shouldn't accept a second connection"); fail("The server shouldn't accept a second connection");
} catch (IOException e) { } catch (IOException e) {
//OK, the clien will close the server socket if successfull //OK, the client will close the server socket if successful
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册