Skip to content

Commit f91b196

Browse files
committed
Add toModifiableCopy to request and response
1 parent 909181c commit f91b196

10 files changed

Lines changed: 32 additions & 22 deletions

File tree

http/http-api/src/main/java/software/amazon/smithy/java/http/api/HttpRequest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ public interface HttpRequest extends HttpMessage {
2727
SmithyUri uri();
2828

2929
/**
30-
* Get a modifiable version of the request.
30+
* Get a modifiable version of the request, or returns the current request if it's already modifiable.
3131
*
32-
* @return the modifiable request.
32+
* @return the modifiable request or current request.
3333
*/
3434
ModifiableHttpRequest toModifiable();
3535

36+
/**
37+
* Creates a modifiable copy of the request, even if the current request is modifiable.
38+
*
39+
* @return the modifiable copy of this request.
40+
*/
41+
ModifiableHttpRequest toModifiableCopy();
42+
3643
/**
3744
* Creates an unmodifiable copy of the request, or returns it as is if it is already unmodifiable.
3845
*

http/http-api/src/main/java/software/amazon/smithy/java/http/api/HttpRequestImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public HttpRequest toUnmodifiable() {
3131

3232
@Override
3333
public ModifiableHttpRequest toModifiable() {
34+
return toModifiableCopy();
35+
}
36+
37+
@Override
38+
public ModifiableHttpRequest toModifiableCopy() {
3439
var mod = new ModifiableHttpRequestImpl();
3540
mod.setHttpVersion(httpVersion);
3641
mod.setMethod(method);
@@ -113,7 +118,7 @@ public HttpRequest build() {
113118
@Override
114119
public ModifiableHttpRequest buildModifiable() {
115120
beforeBuild();
116-
return modifiableHttpRequest.copy();
121+
return modifiableHttpRequest.toModifiableCopy();
117122
}
118123
}
119124
}

http/http-api/src/main/java/software/amazon/smithy/java/http/api/HttpResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public interface HttpResponse extends HttpMessage {
2323
*/
2424
ModifiableHttpResponse toModifiable();
2525

26+
/**
27+
* Creates a modifiable copy of the response, even if the current response is modifiable.
28+
*
29+
* @return the modifiable copy of this response.
30+
*/
31+
ModifiableHttpResponse toModifiableCopy();
32+
2633
/**
2734
* Creates an unmodifiable copy of the request, or returns it as is if it is already unmodifiable.
2835
*

http/http-api/src/main/java/software/amazon/smithy/java/http/api/HttpResponseImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public HttpResponse toUnmodifiable() {
2626

2727
@Override
2828
public ModifiableHttpResponse toModifiable() {
29+
return toModifiableCopy();
30+
}
31+
32+
@Override
33+
public ModifiableHttpResponse toModifiableCopy() {
2934
var mod = new ModifiableHttpResponseImpl();
3035
mod.setHttpVersion(httpVersion);
3136
mod.setStatusCode(statusCode);
@@ -94,7 +99,7 @@ public HttpResponse build() {
9499

95100
@Override
96101
public ModifiableHttpResponse buildModifiable() {
97-
return modifiableResponse.copy();
102+
return modifiableResponse.toModifiableCopy();
98103
}
99104
}
100105
}

http/http-api/src/main/java/software/amazon/smithy/java/http/api/ModifiableHttpRequest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,4 @@ default void setUri(URI uri) {
3939
default ModifiableHttpRequest toModifiable() {
4040
return this;
4141
}
42-
43-
/**
44-
* Create a copy of the modifiable request.
45-
*
46-
* @return the standalone copy.
47-
*/
48-
ModifiableHttpRequest copy();
4942
}

http/http-api/src/main/java/software/amazon/smithy/java/http/api/ModifiableHttpRequestImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public HttpRequest toUnmodifiable() {
8888
}
8989

9090
@Override
91-
public ModifiableHttpRequest copy() {
91+
public ModifiableHttpRequest toModifiableCopy() {
9292
return new ModifiableHttpRequestImpl(this);
9393
}
9494

http/http-api/src/main/java/software/amazon/smithy/java/http/api/ModifiableHttpResponse.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,4 @@ public interface ModifiableHttpResponse extends ModifiableHttpMessage, HttpRespo
2020
default ModifiableHttpResponse toModifiable() {
2121
return this;
2222
}
23-
24-
/**
25-
* Create a copy of the modifiable response.
26-
*
27-
* @return the standalone copy.
28-
*/
29-
ModifiableHttpResponse copy();
3023
}

http/http-api/src/main/java/software/amazon/smithy/java/http/api/ModifiableHttpResponseImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public HttpResponse toUnmodifiable() {
8686
}
8787

8888
@Override
89-
public ModifiableHttpResponse copy() {
89+
public ModifiableHttpResponse toModifiableCopy() {
9090
return new ModifiableHttpResponseImpl(this);
9191
}
9292

http/http-api/src/test/java/software/amazon/smithy/java/http/api/SmithyHttpRequestImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void modifiableCopyIsIndependent() throws Exception {
161161
.withAddedHeader("foo", "bar")
162162
.buildModifiable();
163163

164-
var copy = modifiable.copy();
164+
var copy = modifiable.toModifiableCopy();
165165
copy.headers().addHeader("foo", "baz");
166166

167167
assertThat(modifiable.headers().allValues("foo"), contains("bar"));

http/http-api/src/test/java/software/amazon/smithy/java/http/api/SmithyHttpResponseImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void modifiableCopyIsIndependent() {
150150
.withAddedHeader("foo", "bar")
151151
.buildModifiable();
152152

153-
var copy = modifiable.copy();
153+
var copy = modifiable.toModifiableCopy();
154154
copy.headers().addHeader("foo", "baz");
155155

156156
assertThat(modifiable.headers().allValues("foo"), contains("bar"));

0 commit comments

Comments
 (0)