src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestImpl.java
changeset 58758 2b13d126a2d8
parent 53521 41fa3e6f2785
--- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestImpl.java	Wed Oct 23 15:48:11 2019 +0200
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestImpl.java	Wed Oct 23 15:54:39 2019 +0100
@@ -41,6 +41,7 @@
 import java.net.http.HttpClient;
 import java.net.http.HttpHeaders;
 import java.net.http.HttpRequest;
+
 import jdk.internal.net.http.common.HttpHeadersBuilder;
 import jdk.internal.net.http.common.Utils;
 import jdk.internal.net.http.websocket.OpeningHandshake;
@@ -152,13 +153,14 @@
     /** Returns a new instance suitable for redirection. */
     public static HttpRequestImpl newInstanceForRedirection(URI uri,
                                                             String method,
-                                                            HttpRequestImpl other) {
-        return new HttpRequestImpl(uri, method, other);
+                                                            HttpRequestImpl other,
+                                                            boolean mayHaveBody) {
+        return new HttpRequestImpl(uri, method, other, mayHaveBody);
     }
 
     /** Returns a new instance suitable for authentication. */
     public static HttpRequestImpl newInstanceForAuthentication(HttpRequestImpl other) {
-        HttpRequestImpl request = new HttpRequestImpl(other.uri(), other.method(), other);
+        HttpRequestImpl request = new HttpRequestImpl(other.uri(), other.method(), other, true);
         if (request.isWebSocket()) {
             Utils.setWebSocketUpgradeHeaders(request);
         }
@@ -171,7 +173,8 @@
      */
     private HttpRequestImpl(URI uri,
                             String method,
-                            HttpRequestImpl other) {
+                            HttpRequestImpl other,
+                            boolean mayHaveBody) {
         assert method == null || Utils.isValidName(method);
         this.method = method == null? "GET" : method;
         this.userHeaders = other.userHeaders;
@@ -184,13 +187,21 @@
         this.proxy = other.proxy;
         this.expectContinue = other.expectContinue;
         this.secure = uri.getScheme().toLowerCase(Locale.US).equals("https");
-        this.requestPublisher = other.requestPublisher;  // may be null
+        this.requestPublisher = mayHaveBody ? publisher(other) : null; // may be null
         this.acc = other.acc;
         this.timeout = other.timeout;
         this.version = other.version();
         this.authority = null;
     }
 
+    private BodyPublisher publisher(HttpRequestImpl other) {
+        BodyPublisher res = other.requestPublisher;
+        if (!Objects.equals(method, other.method)) {
+            res = null;
+        }
+        return res;
+    }
+
     /* used for creating CONNECT requests  */
     HttpRequestImpl(String method, InetSocketAddress authority, HttpHeaders headers) {
         // TODO: isWebSocket flag is not specified, but the assumption is that