41
41
import java .net .http .HttpClient ;
42
42
import java .net .http .HttpHeaders ;
43
43
import java .net .http .HttpRequest ;
44
+
44
45
import jdk .internal .net .http .common .HttpHeadersBuilder ;
45
46
import jdk .internal .net .http .common .Utils ;
46
47
import jdk .internal .net .http .websocket .OpeningHandshake ;
@@ -152,13 +153,14 @@ private static void checkTimeout(Duration duration) {
152
153
/** Returns a new instance suitable for redirection. */
153
154
public static HttpRequestImpl newInstanceForRedirection (URI uri ,
154
155
String method ,
155
- HttpRequestImpl other ) {
156
- return new HttpRequestImpl (uri , method , other );
156
+ HttpRequestImpl other ,
157
+ boolean mayHaveBody ) {
158
+ return new HttpRequestImpl (uri , method , other , mayHaveBody );
157
159
}
158
160
159
161
/** Returns a new instance suitable for authentication. */
160
162
public static HttpRequestImpl newInstanceForAuthentication (HttpRequestImpl other ) {
161
- HttpRequestImpl request = new HttpRequestImpl (other .uri (), other .method (), other );
163
+ HttpRequestImpl request = new HttpRequestImpl (other .uri (), other .method (), other , true );
162
164
if (request .isWebSocket ()) {
163
165
Utils .setWebSocketUpgradeHeaders (request );
164
166
}
@@ -171,7 +173,8 @@ public static HttpRequestImpl newInstanceForAuthentication(HttpRequestImpl other
171
173
*/
172
174
private HttpRequestImpl (URI uri ,
173
175
String method ,
174
- HttpRequestImpl other ) {
176
+ HttpRequestImpl other ,
177
+ boolean mayHaveBody ) {
175
178
assert method == null || Utils .isValidName (method );
176
179
this .method = method == null ? "GET" : method ;
177
180
this .userHeaders = other .userHeaders ;
@@ -184,13 +187,21 @@ private HttpRequestImpl(URI uri,
184
187
this .proxy = other .proxy ;
185
188
this .expectContinue = other .expectContinue ;
186
189
this .secure = uri .getScheme ().toLowerCase (Locale .US ).equals ("https" );
187
- this .requestPublisher = other . requestPublisher ; // may be null
190
+ this .requestPublisher = mayHaveBody ? publisher ( other ) : null ; // may be null
188
191
this .acc = other .acc ;
189
192
this .timeout = other .timeout ;
190
193
this .version = other .version ();
191
194
this .authority = null ;
192
195
}
193
196
197
+ private BodyPublisher publisher (HttpRequestImpl other ) {
198
+ BodyPublisher res = other .requestPublisher ;
199
+ if (!Objects .equals (method , other .method )) {
200
+ res = null ;
201
+ }
202
+ return res ;
203
+ }
204
+
194
205
/* used for creating CONNECT requests */
195
206
HttpRequestImpl (String method , InetSocketAddress authority , HttpHeaders headers ) {
196
207
// TODO: isWebSocket flag is not specified, but the assumption is that
0 commit comments