http-client-branch: review comment - request builder copy should not require a URI
--- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestBuilderImpl.java Mon Apr 16 17:30:02 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestBuilderImpl.java Mon Apr 16 18:38:31 2018 +0100
@@ -88,7 +88,8 @@
@Override
public HttpRequestBuilderImpl copy() {
- HttpRequestBuilderImpl b = new HttpRequestBuilderImpl(this.uri);
+ HttpRequestBuilderImpl b = new HttpRequestBuilderImpl();
+ b.uri = this.uri;
b.userHeaders = this.userHeaders.deepCopy();
b.method = this.method;
b.expectContinue = this.expectContinue;
--- a/test/jdk/java/net/httpclient/RequestBuilderTest.java Mon Apr 16 17:30:02 2018 +0100
+++ b/test/jdk/java/net/httpclient/RequestBuilderTest.java Mon Apr 16 18:38:31 2018 +0100
@@ -58,7 +58,9 @@
@Test
public void testDefaults() {
List<HttpRequest.Builder> builders = List.of(newBuilder().uri(uri),
- newBuilder(uri));
+ newBuilder(uri),
+ newBuilder().copy().uri(uri),
+ newBuilder(uri).copy());
for (HttpRequest.Builder builder : builders) {
assertFalse(builder.build().expectContinue());
assertEquals(builder.build().method(), "GET");
@@ -376,6 +378,17 @@
assertEquals(copyRequest.timeout().get(), ofSeconds(30));
assertTrue(copyRequest.version().isPresent());
assertEquals(copyRequest.version().get(), HTTP_1_1);
+
+ // lazy set URI ( maybe builder as a template )
+ copyRequest = newBuilder().copy().uri(uri).build();
+ assertEquals(copyRequest.uri(), uri);
+
+ builder = newBuilder().header("C", "D");
+ copy = builder.copy();
+ copy.uri(uri);
+ copyRequest = copy.build();
+ assertEquals(copyRequest.uri(), uri);
+ assertEquals(copyRequest.headers().firstValue("C").get(), "D");
}
@Test