Skip to content

Commit 0db3175

Browse files
committed
Copy cookies in built ServerResponse
Closes gh-22481
1 parent dba04a7 commit 0db3175

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerResponseBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public DefaultServerResponseBuilder(ServerResponse other) {
7070
this.statusCode = (other instanceof AbstractServerResponse ?
7171
((AbstractServerResponse) other).statusCode : other.statusCode().value());
7272
this.headers.addAll(other.headers());
73+
this.cookies.addAll(other.cookies());
7374
}
7475

7576
public DefaultServerResponseBuilder(HttpStatus status) {

spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ public void status() {
7171

7272
@Test
7373
public void from() {
74-
ServerResponse other = ServerResponse.ok().header("foo", "bar").build();
74+
Cookie cookie = new Cookie("foo", "bar");
75+
ServerResponse other = ServerResponse.ok()
76+
.header("foo", "bar")
77+
.cookie(cookie)
78+
.build();
7579
ServerResponse result = ServerResponse.from(other).build();
7680
assertEquals(HttpStatus.OK, result.statusCode());
7781
assertEquals("bar", result.headers().getFirst("foo"));
82+
assertEquals(cookie, result.cookies().getFirst("foo"));
7883
}
7984

8085

0 commit comments

Comments
 (0)