8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming
authorchegar
Fri, 14 Nov 2014 18:15:52 +0000
changeset 27717 9d29bef916e1
parent 27716 01f9b7007718
child 27718 5e08d0fb67c9
8050983: Misplaced parentheses in sun.net.www.http.HttpClient break HTTP PUT streaming Reviewed-by: michaelm
jdk/src/java.base/share/classes/sun/net/www/http/HttpClient.java
jdk/test/sun/net/www/http/HttpClient/StreamingRetry.java
--- a/jdk/src/java.base/share/classes/sun/net/www/http/HttpClient.java	Fri Nov 14 11:41:42 2014 +0000
+++ b/jdk/src/java.base/share/classes/sun/net/www/http/HttpClient.java	Fri Nov 14 18:15:52 2014 +0000
@@ -657,9 +657,10 @@
             cachedHttpClient = false;
             if (!failedOnce && requests != null) {
                 failedOnce = true;
-                if (getRequestMethod().equals("CONNECT") ||
-                    (httpuc.getRequestMethod().equals("POST") &&
-                    (!retryPostProp || streaming))) {
+                if (getRequestMethod().equals("CONNECT")
+                    || streaming
+                    || (httpuc.getRequestMethod().equals("POST")
+                        && !retryPostProp)) {
                     // do not retry the request
                 }  else {
                     // try once more
@@ -769,9 +770,10 @@
             } else if (nread != 8) {
                 if (!failedOnce && requests != null) {
                     failedOnce = true;
-                    if (getRequestMethod().equals("CONNECT") ||
-                        (httpuc.getRequestMethod().equals("POST") &&
-                         (!retryPostProp || streaming))) {
+                    if (getRequestMethod().equals("CONNECT")
+                        || streaming
+                        || (httpuc.getRequestMethod().equals("POST")
+                            && !retryPostProp)) {
                         // do not retry the request
                     } else {
                         closeServer();
--- a/jdk/test/sun/net/www/http/HttpClient/StreamingRetry.java	Fri Nov 14 11:41:42 2014 +0000
+++ b/jdk/test/sun/net/www/http/HttpClient/StreamingRetry.java	Fri Nov 14 18:15:52 2014 +0000
@@ -23,8 +23,8 @@
 
 /*
  * @test
- * @bug 6672144
- * @summary HttpURLConnection.getInputStream sends POST request after failed chunked send
+ * @bug 6672144 8050983
+ * @summary Do not retry failed request with a streaming body.
  */
 
 import java.net.HttpURLConnection;
@@ -33,6 +33,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import static java.lang.System.out;
 
 public class StreamingRetry implements Runnable {
     static final int ACCEPT_TIMEOUT = 20 * 1000; // 20 seconds
@@ -43,11 +44,17 @@
     }
 
     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");
     }
 
-    void test() throws IOException {
+    void test(String method) throws IOException {
         ss = new ServerSocket(0);
         ss.setSoTimeout(ACCEPT_TIMEOUT);
         int port = ss.getLocalPort();
@@ -58,6 +65,8 @@
             URL url = new URL("http://localhost:" + port + "/");
             HttpURLConnection uc = (HttpURLConnection) url.openConnection();
             uc.setDoOutput(true);
+            if (method != null)
+                uc.setRequestMethod(method);
             uc.setChunkedStreamingMode(4096);
             OutputStream os = uc.getOutputStream();
             os.write("Hello there".getBytes());
@@ -79,7 +88,7 @@
             ss.close();
             fail("The server shouldn't accept a second connection");
          } catch (IOException e) {
-            //OK, the clien will close the server socket if successfull
+            //OK, the client will close the server socket if successful
         }
     }