Copy cookies in built ServerResponse
Closes gh-22481
This commit is contained in:
@@ -70,6 +70,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
|
||||
this.statusCode = (other instanceof AbstractServerResponse ?
|
||||
((AbstractServerResponse) other).statusCode : other.statusCode().value());
|
||||
this.headers.addAll(other.headers());
|
||||
this.cookies.addAll(other.cookies());
|
||||
}
|
||||
|
||||
public DefaultServerResponseBuilder(HttpStatus status) {
|
||||
|
||||
@@ -71,10 +71,15 @@ public class DefaultServerResponseBuilderTests {
|
||||
|
||||
@Test
|
||||
public void from() {
|
||||
ServerResponse other = ServerResponse.ok().header("foo", "bar").build();
|
||||
Cookie cookie = new Cookie("foo", "bar");
|
||||
ServerResponse other = ServerResponse.ok()
|
||||
.header("foo", "bar")
|
||||
.cookie(cookie)
|
||||
.build();
|
||||
ServerResponse result = ServerResponse.from(other).build();
|
||||
assertEquals(HttpStatus.OK, result.statusCode());
|
||||
assertEquals("bar", result.headers().getFirst("foo"));
|
||||
assertEquals(cookie, result.cookies().getFirst("foo"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user