Add Partitioned cookie attribute support for servers

This commit adds support for the "Partitioned" cookie attribute in
WebFlux servers and the related testing infrastructure.
Note, Undertow does not support this feature at the moment.

Closes gh-31454
This commit is contained in:
Brian Clozel
2024-06-07 10:03:52 +02:00
parent 2aabe238c6
commit 7fc4937199
18 changed files with 178 additions and 10 deletions

View File

@@ -98,6 +98,24 @@ public class MockCookie extends Cookie {
return getAttribute(SAME_SITE);
}
/**
* Set the "Partitioned" attribute for this cookie.
* @since 6.2
* @see <a href="https://datatracker.ietf.org/doc/html/draft-cutler-httpbis-partitioned-cookies#section-2.1">The Partitioned attribute spec</a>
*/
public void setPartitioned(boolean partitioned) {
setAttribute("Partitioned", "");
}
/**
* Return whether the "Partitioned" attribute is set for this cookie.
* @since 6.2
* @see <a href="https://datatracker.ietf.org/doc/html/draft-cutler-httpbis-partitioned-cookies#section-2.1">The Partitioned attribute spec</a>
*/
public boolean isPartitioned() {
return getAttribute("Partitioned") != null;
}
/**
* Factory method that parses the value of the supplied "Set-Cookie" header.
* @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
@@ -146,6 +164,9 @@ public class MockCookie extends Cookie {
else if (StringUtils.startsWithIgnoreCase(attribute, "Comment")) {
cookie.setComment(extractAttributeValue(attribute, setCookieHeader));
}
else {
cookie.setAttribute(attribute, extractAttributeValue(attribute, setCookieHeader));
}
}
return cookie;
}

View File

@@ -481,6 +481,9 @@ public class MockHttpServletResponse implements HttpServletResponse {
if (cookie.isHttpOnly()) {
buf.append("; HttpOnly");
}
if (cookie.getAttribute("Partitioned") != null) {
buf.append("; Partitioned");
}
if (cookie instanceof MockCookie mockCookie) {
if (StringUtils.hasText(mockCookie.getSameSite())) {
buf.append("; SameSite=").append(mockCookie.getSameSite());