Rename ServerCookie to ResponseCookie
HttpCookie-ResponseCookie follows HttpEntity-ResponseEntity and also avoids use of "Server" outside of server sub-package.
This commit is contained in:
@@ -18,10 +18,9 @@ package org.springframework.http;
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an HTTP Cookie with a name and value.
|
* 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
|
||||||
* <p>The {@link ServerHttpCookie} sub-class exposes the extra attributes that
|
* additional attributes expected in the "Set-Cookie" response header.
|
||||||
* a server can include in a Set-Cookie response header.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @see <a href="https://tools.ietf.org/html/rfc6265">RFC 6265</a>
|
* @see <a href="https://tools.ietf.org/html/rfc6265">RFC 6265</a>
|
||||||
|
|||||||
@@ -22,15 +22,14 @@ import org.springframework.util.Assert;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a server-side cookie with extra attributes that a server can
|
* An {@code HttpCookie} sub-class with the additional attributes allowed in
|
||||||
* include in a Set-Cookie response header.
|
* the "Set-Cookie" response header. To build an instance use the {@link #from}
|
||||||
*
|
* static method.
|
||||||
* <p>Use {@link #with} to create a {@code ServerHttpCookie}.
|
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @see <a href="https://tools.ietf.org/html/rfc6265">RFC 6265</a>
|
* @see <a href="https://tools.ietf.org/html/rfc6265">RFC 6265</a>
|
||||||
*/
|
*/
|
||||||
public final class ServerHttpCookie extends HttpCookie {
|
public final class ResponseCookie extends HttpCookie {
|
||||||
|
|
||||||
private final Duration maxAge;
|
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) {
|
String path, boolean secure, boolean httpOnly) {
|
||||||
|
|
||||||
super(name, value);
|
super(name, value);
|
||||||
@@ -113,10 +112,10 @@ public final class ServerHttpCookie extends HttpCookie {
|
|||||||
if (this == other) {
|
if (this == other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!(other instanceof ServerHttpCookie)) {
|
if (!(other instanceof ResponseCookie)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ServerHttpCookie otherCookie = (ServerHttpCookie) other;
|
ResponseCookie otherCookie = (ResponseCookie) other;
|
||||||
return (getName().equalsIgnoreCase(otherCookie.getName()) &&
|
return (getName().equalsIgnoreCase(otherCookie.getName()) &&
|
||||||
ObjectUtils.nullSafeEquals(this.path, otherCookie.getPath()) &&
|
ObjectUtils.nullSafeEquals(this.path, otherCookie.getPath()) &&
|
||||||
ObjectUtils.nullSafeEquals(this.domain, otherCookie.getDomain()));
|
ObjectUtils.nullSafeEquals(this.domain, otherCookie.getDomain()));
|
||||||
@@ -130,9 +129,9 @@ public final class ServerHttpCookie extends HttpCookie {
|
|||||||
* @param value the cookie value
|
* @param value the cookie value
|
||||||
* @return the created cookie instance
|
* @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);
|
private Duration maxAge = Duration.ofSeconds(-1);
|
||||||
|
|
||||||
@@ -146,38 +145,38 @@ public final class ServerHttpCookie extends HttpCookie {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerHttpCookieBuilder maxAge(Duration maxAge) {
|
public ResponseCookieBuilder maxAge(Duration maxAge) {
|
||||||
this.maxAge = maxAge;
|
this.maxAge = maxAge;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerHttpCookieBuilder domain(String domain) {
|
public ResponseCookieBuilder domain(String domain) {
|
||||||
this.domain = domain;
|
this.domain = domain;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerHttpCookieBuilder path(String path) {
|
public ResponseCookieBuilder path(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerHttpCookieBuilder secure() {
|
public ResponseCookieBuilder secure() {
|
||||||
this.secure = true;
|
this.secure = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerHttpCookieBuilder httpOnly() {
|
public ResponseCookieBuilder httpOnly() {
|
||||||
this.httpOnly = true;
|
this.httpOnly = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerHttpCookie build() {
|
public ResponseCookie build() {
|
||||||
return new ServerHttpCookie(name, value, this.maxAge, this.domain, this.path,
|
return new ResponseCookie(name, value, this.maxAge, this.domain, this.path,
|
||||||
this.secure, this.httpOnly);
|
this.secure, this.httpOnly);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -186,7 +185,7 @@ public final class ServerHttpCookie extends HttpCookie {
|
|||||||
/**
|
/**
|
||||||
* A builder for a server-defined HttpCookie with attributes.
|
* A builder for a server-defined HttpCookie with attributes.
|
||||||
*/
|
*/
|
||||||
public interface ServerHttpCookieBuilder {
|
public interface ResponseCookieBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the cookie "Max-Age" attribute.
|
* 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
|
* immediately. A negative value results in no "Max-Age" attribute in
|
||||||
* which case the cookie is removed when the browser is closed.
|
* which case the cookie is removed when the browser is closed.
|
||||||
*/
|
*/
|
||||||
ServerHttpCookieBuilder maxAge(Duration maxAge);
|
ResponseCookieBuilder maxAge(Duration maxAge);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the cookie "Path" attribute.
|
* Set the cookie "Path" attribute.
|
||||||
*/
|
*/
|
||||||
ServerHttpCookieBuilder path(String path);
|
ResponseCookieBuilder path(String path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the cookie "Domain" attribute.
|
* Set the cookie "Domain" attribute.
|
||||||
*/
|
*/
|
||||||
ServerHttpCookieBuilder domain(String domain);
|
ResponseCookieBuilder domain(String domain);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the "Secure" attribute to the cookie.
|
* Add the "Secure" attribute to the cookie.
|
||||||
*/
|
*/
|
||||||
ServerHttpCookieBuilder secure();
|
ResponseCookieBuilder secure();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the "HttpOnly" attribute to the cookie.
|
* Add the "HttpOnly" attribute to the cookie.
|
||||||
* @see <a href="http://www.owasp.org/index.php/HTTPOnly">http://www.owasp.org/index.php/HTTPOnly</a>
|
* @see <a href="http://www.owasp.org/index.php/HTTPOnly">http://www.owasp.org/index.php/HTTPOnly</a>
|
||||||
*/
|
*/
|
||||||
ServerHttpCookieBuilder httpOnly();
|
ResponseCookieBuilder httpOnly();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the HttpCookie.
|
* Create the HttpCookie.
|
||||||
*/
|
*/
|
||||||
ServerHttpCookie build();
|
ResponseCookie build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,6 @@ package org.springframework.http.server.reactive;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@@ -25,9 +24,8 @@ import org.reactivestreams.Publisher;
|
|||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.http.HttpCookie;
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
@@ -43,7 +41,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
|
|||||||
|
|
||||||
private final HttpHeaders headers;
|
private final HttpHeaders headers;
|
||||||
|
|
||||||
private final MultiValueMap<String, ServerHttpCookie> cookies;
|
private final MultiValueMap<String, ResponseCookie> cookies;
|
||||||
|
|
||||||
private AtomicReference<State> state = new AtomicReference<>(State.NEW);
|
private AtomicReference<State> state = new AtomicReference<>(State.NEW);
|
||||||
|
|
||||||
@@ -52,7 +50,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
|
|||||||
|
|
||||||
protected AbstractServerHttpResponse() {
|
protected AbstractServerHttpResponse() {
|
||||||
this.headers = new HttpHeaders();
|
this.headers = new HttpHeaders();
|
||||||
this.cookies = new LinkedMultiValueMap<String, ServerHttpCookie>();
|
this.cookies = new LinkedMultiValueMap<String, ResponseCookie>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +63,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiValueMap<String, ServerHttpCookie> getCookies() {
|
public MultiValueMap<String, ResponseCookie> getCookies() {
|
||||||
if (State.COMITTED.equals(this.state.get())) {
|
if (State.COMITTED.equals(this.state.get())) {
|
||||||
return CollectionUtils.unmodifiableMultiValueMap(this.cookies);
|
return CollectionUtils.unmodifiableMultiValueMap(this.cookies);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import reactor.io.netty.http.model.Status;
|
|||||||
|
|
||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,7 +75,7 @@ public class ReactorServerHttpResponse extends AbstractServerHttpResponse {
|
|||||||
@Override
|
@Override
|
||||||
protected void writeCookies() {
|
protected void writeCookies() {
|
||||||
for (String name : getCookies().keySet()) {
|
for (String name : getCookies().keySet()) {
|
||||||
for (ServerHttpCookie httpCookie : getCookies().get(name)) {
|
for (ResponseCookie httpCookie : getCookies().get(name)) {
|
||||||
Cookie cookie = new ReactorCookie(httpCookie);
|
Cookie cookie = new ReactorCookie(httpCookie);
|
||||||
this.channel.addResponseCookie(name, cookie);
|
this.channel.addResponseCookie(name, cookie);
|
||||||
}
|
}
|
||||||
@@ -88,10 +88,10 @@ public class ReactorServerHttpResponse extends AbstractServerHttpResponse {
|
|||||||
*/
|
*/
|
||||||
private final static class ReactorCookie extends Cookie {
|
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;
|
this.httpCookie = httpCookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import rx.Observable;
|
|||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.core.io.buffer.NettyDataBuffer;
|
import org.springframework.core.io.buffer.NettyDataBuffer;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +86,7 @@ public class RxNettyServerHttpResponse extends AbstractServerHttpResponse {
|
|||||||
@Override
|
@Override
|
||||||
protected void writeCookies() {
|
protected void writeCookies() {
|
||||||
for (String name : getCookies().keySet()) {
|
for (String name : getCookies().keySet()) {
|
||||||
for (ServerHttpCookie httpCookie : getCookies().get(name)) {
|
for (ResponseCookie httpCookie : getCookies().get(name)) {
|
||||||
Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
|
Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
|
||||||
if (!httpCookie.getMaxAge().isNegative()) {
|
if (!httpCookie.getMaxAge().isNegative()) {
|
||||||
cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
|
cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
|
||||||
|
|||||||
@@ -16,15 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.http.server.reactive;
|
package org.springframework.http.server.reactive;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import org.springframework.http.HttpCookie;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ReactiveHttpOutputMessage;
|
import org.springframework.http.ReactiveHttpOutputMessage;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.util.MultiValueMap;
|
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.
|
* Return a mutable map with cookies to be sent to the client.
|
||||||
*/
|
*/
|
||||||
MultiValueMap<String, ServerHttpCookie> getCookies();
|
MultiValueMap<String, ResponseCookie> getCookies();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicate that request handling is complete, allowing for any cleanup or
|
* Indicate that request handling is complete, allowing for any cleanup or
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import reactor.core.publisher.Mono;
|
|||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +99,7 @@ public class ServletServerHttpResponse extends AbstractServerHttpResponse {
|
|||||||
@Override
|
@Override
|
||||||
protected void writeCookies() {
|
protected void writeCookies() {
|
||||||
for (String name : getCookies().keySet()) {
|
for (String name : getCookies().keySet()) {
|
||||||
for (ServerHttpCookie httpCookie : getCookies().get(name)) {
|
for (ResponseCookie httpCookie : getCookies().get(name)) {
|
||||||
Cookie cookie = new Cookie(name, httpCookie.getValue());
|
Cookie cookie = new Cookie(name, httpCookie.getValue());
|
||||||
if (!httpCookie.getMaxAge().isNegative()) {
|
if (!httpCookie.getMaxAge().isNegative()) {
|
||||||
cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds());
|
cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds());
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import reactor.core.publisher.Mono;
|
|||||||
|
|
||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,7 +81,7 @@ public class UndertowServerHttpResponse extends AbstractServerHttpResponse {
|
|||||||
@Override
|
@Override
|
||||||
protected void writeCookies() {
|
protected void writeCookies() {
|
||||||
for (String name : getCookies().keySet()) {
|
for (String name : getCookies().keySet()) {
|
||||||
for (ServerHttpCookie httpCookie : getCookies().get(name)) {
|
for (ResponseCookie httpCookie : getCookies().get(name)) {
|
||||||
Cookie cookie = new CookieImpl(name, httpCookie.getValue());
|
Cookie cookie = new CookieImpl(name, httpCookie.getValue());
|
||||||
if (!httpCookie.getMaxAge().isNegative()) {
|
if (!httpCookie.getMaxAge().isNegative()) {
|
||||||
cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds());
|
cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds());
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.springframework.http.HttpCookie;
|
import org.springframework.http.HttpCookie;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.util.StringUtils;
|
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
|
* 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()}.
|
||||||
* <p>By default set to -1.
|
* <p>By default set to -1.
|
||||||
* @param maxAge the maxAge duration value
|
* @param maxAge the maxAge duration value
|
||||||
*/
|
*/
|
||||||
@@ -87,8 +87,8 @@ public class CookieWebSessionIdResolver implements WebSessionIdResolver {
|
|||||||
@Override
|
@Override
|
||||||
public void setSessionId(ServerWebExchange exchange, String id) {
|
public void setSessionId(ServerWebExchange exchange, String id) {
|
||||||
Duration maxAge = (StringUtils.hasText(id) ? getCookieMaxAge() : Duration.ofSeconds(0));
|
Duration maxAge = (StringUtils.hasText(id) ? getCookieMaxAge() : Duration.ofSeconds(0));
|
||||||
ServerHttpCookie cookie = ServerHttpCookie.with(getCookieName(), id).maxAge(maxAge).build();
|
ResponseCookie cookie = ResponseCookie.from(getCookieName(), id).maxAge(maxAge).build();
|
||||||
MultiValueMap<String, ServerHttpCookie> cookieMap = exchange.getResponse().getCookies();
|
MultiValueMap<String, ResponseCookie> cookieMap = exchange.getResponse().getCookies();
|
||||||
cookieMap.set(getCookieName(), cookie);
|
cookieMap.set(getCookieName(), cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import reactor.core.publisher.Mono;
|
|||||||
import org.springframework.http.HttpCookie;
|
import org.springframework.http.HttpCookie;
|
||||||
import org.springframework.http.RequestEntity;
|
import org.springframework.http.RequestEntity;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
@@ -102,9 +102,9 @@ public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests
|
|||||||
this.requestCookies = request.getCookies();
|
this.requestCookies = request.getCookies();
|
||||||
this.requestCookies.size(); // Cause lazy loading
|
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());
|
.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());
|
.domain("example.com").path("/").build());
|
||||||
|
|
||||||
return response.setComplete();
|
return response.setComplete();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import reactor.core.publisher.Mono;
|
|||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class MockServerHttpResponse implements ServerHttpResponse {
|
|||||||
|
|
||||||
private HttpHeaders headers = new HttpHeaders();
|
private HttpHeaders headers = new HttpHeaders();
|
||||||
|
|
||||||
private MultiValueMap<String, ServerHttpCookie> cookies = new LinkedMultiValueMap<>();
|
private MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>();
|
||||||
|
|
||||||
private Publisher<DataBuffer> body;
|
private Publisher<DataBuffer> body;
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ public class MockServerHttpResponse implements ServerHttpResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiValueMap<String, ServerHttpCookie> getCookies() {
|
public MultiValueMap<String, ResponseCookie> getCookies() {
|
||||||
return this.cookies;
|
return this.cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import reactor.core.publisher.Mono;
|
|||||||
import org.springframework.core.io.buffer.DataBuffer;
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.core.io.buffer.DefaultDataBufferAllocator;
|
import org.springframework.core.io.buffer.DefaultDataBufferAllocator;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ServerHttpCookie;
|
import org.springframework.http.ResponseCookie;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertTrue;
|
import static junit.framework.TestCase.assertTrue;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -81,7 +81,7 @@ public class ServerHttpResponseTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void beforeCommitWithSetBody() throws Exception {
|
public void beforeCommitWithSetBody() throws Exception {
|
||||||
ServerHttpCookie cookie = ServerHttpCookie.with("ID", "123").build();
|
ResponseCookie cookie = ResponseCookie.from("ID", "123").build();
|
||||||
TestServerHttpResponse response = new TestServerHttpResponse();
|
TestServerHttpResponse response = new TestServerHttpResponse();
|
||||||
response.beforeCommit(() -> {
|
response.beforeCommit(() -> {
|
||||||
response.getCookies().add(cookie.getName(), cookie);
|
response.getCookies().add(cookie.getName(), cookie);
|
||||||
@@ -118,7 +118,7 @@ public class ServerHttpResponseTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void beforeCommitActionWithSetComplete() throws Exception {
|
public void beforeCommitActionWithSetComplete() throws Exception {
|
||||||
ServerHttpCookie cookie = ServerHttpCookie.with("ID", "123").build();
|
ResponseCookie cookie = ResponseCookie.from("ID", "123").build();
|
||||||
TestServerHttpResponse response = new TestServerHttpResponse();
|
TestServerHttpResponse response = new TestServerHttpResponse();
|
||||||
response.beforeCommit(() -> {
|
response.beforeCommit(() -> {
|
||||||
response.getCookies().add(cookie.getName(), cookie);
|
response.getCookies().add(cookie.getName(), cookie);
|
||||||
|
|||||||
Reference in New Issue
Block a user