diff --git a/spring-web-reactive/src/main/java/org/springframework/http/HttpCookie.java b/spring-web-reactive/src/main/java/org/springframework/http/HttpCookie.java
index 3f1675a4a9c..34f57ae8be3 100644
--- a/spring-web-reactive/src/main/java/org/springframework/http/HttpCookie.java
+++ b/spring-web-reactive/src/main/java/org/springframework/http/HttpCookie.java
@@ -18,10 +18,9 @@ package org.springframework.http;
import org.springframework.util.Assert;
/**
- * Represents an HTTP Cookie with a name and value.
- *
- *
The {@link ServerHttpCookie} sub-class exposes the extra attributes that
- * a server can include in a Set-Cookie response header.
+ * Represents an HTTP cookie as a name-value pair consistent with the content of
+ * the "Cookie" request header. The {@link ResponseCookie} sub-class has the
+ * additional attributes expected in the "Set-Cookie" response header.
*
* @author Rossen Stoyanchev
* @see RFC 6265
diff --git a/spring-web-reactive/src/main/java/org/springframework/http/ServerHttpCookie.java b/spring-web-reactive/src/main/java/org/springframework/http/ResponseCookie.java
similarity index 77%
rename from spring-web-reactive/src/main/java/org/springframework/http/ServerHttpCookie.java
rename to spring-web-reactive/src/main/java/org/springframework/http/ResponseCookie.java
index 4d7d698d6e5..13d9adbc45c 100644
--- a/spring-web-reactive/src/main/java/org/springframework/http/ServerHttpCookie.java
+++ b/spring-web-reactive/src/main/java/org/springframework/http/ResponseCookie.java
@@ -22,15 +22,14 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
- * Represents a server-side cookie with extra attributes that a server can
- * include in a Set-Cookie response header.
- *
- *
Use {@link #with} to create a {@code ServerHttpCookie}.
+ * An {@code HttpCookie} sub-class with the additional attributes allowed in
+ * the "Set-Cookie" response header. To build an instance use the {@link #from}
+ * static method.
*
* @author Rossen Stoyanchev
* @see RFC 6265
*/
-public final class ServerHttpCookie extends HttpCookie {
+public final class ResponseCookie extends HttpCookie {
private final Duration maxAge;
@@ -44,9 +43,9 @@ public final class ServerHttpCookie extends HttpCookie {
/**
- * Private constructor. See {@link #with(String, String)}.
+ * Private constructor. See {@link #from(String, String)}.
*/
- private ServerHttpCookie(String name, String value, Duration maxAge, String domain,
+ private ResponseCookie(String name, String value, Duration maxAge, String domain,
String path, boolean secure, boolean httpOnly) {
super(name, value);
@@ -113,10 +112,10 @@ public final class ServerHttpCookie extends HttpCookie {
if (this == other) {
return true;
}
- if (!(other instanceof ServerHttpCookie)) {
+ if (!(other instanceof ResponseCookie)) {
return false;
}
- ServerHttpCookie otherCookie = (ServerHttpCookie) other;
+ ResponseCookie otherCookie = (ResponseCookie) other;
return (getName().equalsIgnoreCase(otherCookie.getName()) &&
ObjectUtils.nullSafeEquals(this.path, otherCookie.getPath()) &&
ObjectUtils.nullSafeEquals(this.domain, otherCookie.getDomain()));
@@ -130,9 +129,9 @@ public final class ServerHttpCookie extends HttpCookie {
* @param value the cookie value
* @return the created cookie instance
*/
- public static ServerHttpCookieBuilder with(final String name, final String value) {
+ public static ResponseCookieBuilder from(final String name, final String value) {
- return new ServerHttpCookieBuilder() {
+ return new ResponseCookieBuilder() {
private Duration maxAge = Duration.ofSeconds(-1);
@@ -146,38 +145,38 @@ public final class ServerHttpCookie extends HttpCookie {
@Override
- public ServerHttpCookieBuilder maxAge(Duration maxAge) {
+ public ResponseCookieBuilder maxAge(Duration maxAge) {
this.maxAge = maxAge;
return this;
}
@Override
- public ServerHttpCookieBuilder domain(String domain) {
+ public ResponseCookieBuilder domain(String domain) {
this.domain = domain;
return this;
}
@Override
- public ServerHttpCookieBuilder path(String path) {
+ public ResponseCookieBuilder path(String path) {
this.path = path;
return this;
}
@Override
- public ServerHttpCookieBuilder secure() {
+ public ResponseCookieBuilder secure() {
this.secure = true;
return this;
}
@Override
- public ServerHttpCookieBuilder httpOnly() {
+ public ResponseCookieBuilder httpOnly() {
this.httpOnly = true;
return this;
}
@Override
- public ServerHttpCookie build() {
- return new ServerHttpCookie(name, value, this.maxAge, this.domain, this.path,
+ public ResponseCookie build() {
+ return new ResponseCookie(name, value, this.maxAge, this.domain, this.path,
this.secure, this.httpOnly);
}
};
@@ -186,7 +185,7 @@ public final class ServerHttpCookie extends HttpCookie {
/**
* A builder for a server-defined HttpCookie with attributes.
*/
- public interface ServerHttpCookieBuilder {
+ public interface ResponseCookieBuilder {
/**
* Set the cookie "Max-Age" attribute.
@@ -196,33 +195,33 @@ public final class ServerHttpCookie extends HttpCookie {
* immediately. A negative value results in no "Max-Age" attribute in
* which case the cookie is removed when the browser is closed.
*/
- ServerHttpCookieBuilder maxAge(Duration maxAge);
+ ResponseCookieBuilder maxAge(Duration maxAge);
/**
* Set the cookie "Path" attribute.
*/
- ServerHttpCookieBuilder path(String path);
+ ResponseCookieBuilder path(String path);
/**
* Set the cookie "Domain" attribute.
*/
- ServerHttpCookieBuilder domain(String domain);
+ ResponseCookieBuilder domain(String domain);
/**
* Add the "Secure" attribute to the cookie.
*/
- ServerHttpCookieBuilder secure();
+ ResponseCookieBuilder secure();
/**
* Add the "HttpOnly" attribute to the cookie.
* @see http://www.owasp.org/index.php/HTTPOnly
*/
- ServerHttpCookieBuilder httpOnly();
+ ResponseCookieBuilder httpOnly();
/**
* Create the HttpCookie.
*/
- ServerHttpCookie build();
+ ResponseCookie build();
}
}
diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java
index e4eb3e4febc..91eff4024ec 100644
--- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java
+++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java
@@ -17,7 +17,6 @@ package org.springframework.http.server.reactive;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
@@ -25,9 +24,8 @@ import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
-import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
@@ -43,7 +41,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
private final HttpHeaders headers;
- private final MultiValueMap cookies;
+ private final MultiValueMap cookies;
private AtomicReference state = new AtomicReference<>(State.NEW);
@@ -52,7 +50,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
protected AbstractServerHttpResponse() {
this.headers = new HttpHeaders();
- this.cookies = new LinkedMultiValueMap();
+ this.cookies = new LinkedMultiValueMap();
}
@@ -65,7 +63,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
}
@Override
- public MultiValueMap getCookies() {
+ public MultiValueMap getCookies() {
if (State.COMITTED.equals(this.state.get())) {
return CollectionUtils.unmodifiableMultiValueMap(this.cookies);
}
diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java
index 0e57f1e2c7a..e2f220c1378 100644
--- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java
+++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java
@@ -28,7 +28,7 @@ import reactor.io.netty.http.model.Status;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.util.Assert;
/**
@@ -75,7 +75,7 @@ public class ReactorServerHttpResponse extends AbstractServerHttpResponse {
@Override
protected void writeCookies() {
for (String name : getCookies().keySet()) {
- for (ServerHttpCookie httpCookie : getCookies().get(name)) {
+ for (ResponseCookie httpCookie : getCookies().get(name)) {
Cookie cookie = new ReactorCookie(httpCookie);
this.channel.addResponseCookie(name, cookie);
}
@@ -88,10 +88,10 @@ public class ReactorServerHttpResponse extends AbstractServerHttpResponse {
*/
private final static class ReactorCookie extends Cookie {
- private final ServerHttpCookie httpCookie;
+ private final ResponseCookie httpCookie;
- public ReactorCookie(ServerHttpCookie httpCookie) {
+ public ReactorCookie(ResponseCookie httpCookie) {
this.httpCookie = httpCookie;
}
diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java
index 9cb04d6719e..ebcf5fad1bc 100644
--- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java
+++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/RxNettyServerHttpResponse.java
@@ -30,7 +30,7 @@ import rx.Observable;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.NettyDataBuffer;
import org.springframework.http.HttpStatus;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.util.Assert;
/**
@@ -86,7 +86,7 @@ public class RxNettyServerHttpResponse extends AbstractServerHttpResponse {
@Override
protected void writeCookies() {
for (String name : getCookies().keySet()) {
- for (ServerHttpCookie httpCookie : getCookies().get(name)) {
+ for (ResponseCookie httpCookie : getCookies().get(name)) {
Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
if (!httpCookie.getMaxAge().isNegative()) {
cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java
index c6d53276e80..18ba0f172b7 100644
--- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java
+++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServerHttpResponse.java
@@ -16,15 +16,11 @@
package org.springframework.http.server.reactive;
-import java.util.List;
-import java.util.Map;
-
import reactor.core.publisher.Mono;
-import org.springframework.http.HttpCookie;
import org.springframework.http.HttpStatus;
import org.springframework.http.ReactiveHttpOutputMessage;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.util.MultiValueMap;
/**
@@ -43,7 +39,7 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage {
/**
* Return a mutable map with cookies to be sent to the client.
*/
- MultiValueMap getCookies();
+ MultiValueMap getCookies();
/**
* Indicate that request handling is complete, allowing for any cleanup or
diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java
index 3c0a5fd9cfd..465a73eff31 100644
--- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java
+++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java
@@ -36,7 +36,7 @@ import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.util.Assert;
/**
@@ -99,7 +99,7 @@ public class ServletServerHttpResponse extends AbstractServerHttpResponse {
@Override
protected void writeCookies() {
for (String name : getCookies().keySet()) {
- for (ServerHttpCookie httpCookie : getCookies().get(name)) {
+ for (ResponseCookie httpCookie : getCookies().get(name)) {
Cookie cookie = new Cookie(name, httpCookie.getValue());
if (!httpCookie.getMaxAge().isNegative()) {
cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds());
diff --git a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java
index 091bf80fddc..910f913f70d 100644
--- a/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java
+++ b/spring-web-reactive/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java
@@ -29,7 +29,7 @@ import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.util.Assert;
/**
@@ -81,7 +81,7 @@ public class UndertowServerHttpResponse extends AbstractServerHttpResponse {
@Override
protected void writeCookies() {
for (String name : getCookies().keySet()) {
- for (ServerHttpCookie httpCookie : getCookies().get(name)) {
+ for (ResponseCookie httpCookie : getCookies().get(name)) {
Cookie cookie = new CookieImpl(name, httpCookie.getValue());
if (!httpCookie.getMaxAge().isNegative()) {
cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds());
diff --git a/spring-web-reactive/src/main/java/org/springframework/web/server/session/CookieWebSessionIdResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/server/session/CookieWebSessionIdResolver.java
index 1d1fe75bad4..a992f0057d6 100644
--- a/spring-web-reactive/src/main/java/org/springframework/web/server/session/CookieWebSessionIdResolver.java
+++ b/spring-web-reactive/src/main/java/org/springframework/web/server/session/CookieWebSessionIdResolver.java
@@ -21,7 +21,7 @@ import java.util.List;
import java.util.stream.Collectors;
import org.springframework.http.HttpCookie;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
@@ -58,7 +58,7 @@ public class CookieWebSessionIdResolver implements WebSessionIdResolver {
/**
* Set the value for the "Max-Age" attribute of the cookie that holds the
- * session id. For the range of values see {@link ServerHttpCookie#getMaxAge()}.
+ * session id. For the range of values see {@link ResponseCookie#getMaxAge()}.
* By default set to -1.
* @param maxAge the maxAge duration value
*/
@@ -87,8 +87,8 @@ public class CookieWebSessionIdResolver implements WebSessionIdResolver {
@Override
public void setSessionId(ServerWebExchange exchange, String id) {
Duration maxAge = (StringUtils.hasText(id) ? getCookieMaxAge() : Duration.ofSeconds(0));
- ServerHttpCookie cookie = ServerHttpCookie.with(getCookieName(), id).maxAge(maxAge).build();
- MultiValueMap cookieMap = exchange.getResponse().getCookies();
+ ResponseCookie cookie = ResponseCookie.from(getCookieName(), id).maxAge(maxAge).build();
+ MultiValueMap cookieMap = exchange.getResponse().getCookies();
cookieMap.set(getCookieName(), cookie);
}
diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java
index 547a6f0457c..db9e79a3c04 100644
--- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java
+++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java
@@ -28,7 +28,7 @@ import reactor.core.publisher.Mono;
import org.springframework.http.HttpCookie;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.web.client.RestTemplate;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -102,9 +102,9 @@ public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests
this.requestCookies = request.getCookies();
this.requestCookies.size(); // Cause lazy loading
- response.getCookies().add("SID", ServerHttpCookie.with("SID", "31d4d96e407aad42")
+ response.getCookies().add("SID", ResponseCookie.from("SID", "31d4d96e407aad42")
.path("/").secure().httpOnly().build());
- response.getCookies().add("lang", ServerHttpCookie.with("lang", "en-US")
+ response.getCookies().add("lang", ResponseCookie.from("lang", "en-US")
.domain("example.com").path("/").build());
return response.setComplete();
diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java
index 995846464ba..42a672ce8d9 100644
--- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java
+++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/MockServerHttpResponse.java
@@ -24,7 +24,7 @@ import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -37,7 +37,7 @@ public class MockServerHttpResponse implements ServerHttpResponse {
private HttpHeaders headers = new HttpHeaders();
- private MultiValueMap cookies = new LinkedMultiValueMap<>();
+ private MultiValueMap cookies = new LinkedMultiValueMap<>();
private Publisher body;
@@ -57,7 +57,7 @@ public class MockServerHttpResponse implements ServerHttpResponse {
}
@Override
- public MultiValueMap getCookies() {
+ public MultiValueMap getCookies() {
return this.cookies;
}
diff --git a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java
index 260e18bdb28..dc2f5bf1b39 100644
--- a/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java
+++ b/spring-web-reactive/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java
@@ -28,7 +28,7 @@ import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DefaultDataBufferAllocator;
import org.springframework.http.HttpStatus;
-import org.springframework.http.ServerHttpCookie;
+import org.springframework.http.ResponseCookie;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
@@ -81,7 +81,7 @@ public class ServerHttpResponseTests {
@Test
public void beforeCommitWithSetBody() throws Exception {
- ServerHttpCookie cookie = ServerHttpCookie.with("ID", "123").build();
+ ResponseCookie cookie = ResponseCookie.from("ID", "123").build();
TestServerHttpResponse response = new TestServerHttpResponse();
response.beforeCommit(() -> {
response.getCookies().add(cookie.getName(), cookie);
@@ -118,7 +118,7 @@ public class ServerHttpResponseTests {
@Test
public void beforeCommitActionWithSetComplete() throws Exception {
- ServerHttpCookie cookie = ServerHttpCookie.with("ID", "123").build();
+ ResponseCookie cookie = ResponseCookie.from("ID", "123").build();
TestServerHttpResponse response = new TestServerHttpResponse();
response.beforeCommit(() -> {
response.getCookies().add(cookie.getName(), cookie);