|
|
|
|
@ -43,9 +43,16 @@ public class MockCookie extends Cookie {
@@ -43,9 +43,16 @@ public class MockCookie extends Cookie {
|
|
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 4312531139502726325L; |
|
|
|
|
|
|
|
|
|
private static final String PATH = "Path"; |
|
|
|
|
private static final String DOMAIN = "Domain"; |
|
|
|
|
private static final String COMMENT = "Comment"; |
|
|
|
|
private static final String SECURE = "Secure"; |
|
|
|
|
private static final String HTTP_ONLY = "HttpOnly"; |
|
|
|
|
private static final String PARTITIONED = "Partitioned"; |
|
|
|
|
private static final String SAME_SITE = "SameSite"; |
|
|
|
|
private static final String MAX_AGE = "Max-Age"; |
|
|
|
|
private static final String EXPIRES = "Expires"; |
|
|
|
|
private static final String PARTITIONED = "Partitioned"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
private ZonedDateTime expires; |
|
|
|
|
@ -140,10 +147,10 @@ public class MockCookie extends Cookie {
@@ -140,10 +147,10 @@ public class MockCookie extends Cookie {
|
|
|
|
|
|
|
|
|
|
MockCookie cookie = new MockCookie(name, value); |
|
|
|
|
for (String attribute : attributes) { |
|
|
|
|
if (StringUtils.startsWithIgnoreCase(attribute, "Domain")) { |
|
|
|
|
if (StringUtils.startsWithIgnoreCase(attribute, DOMAIN)) { |
|
|
|
|
cookie.setDomain(extractAttributeValue(attribute, setCookieHeader)); |
|
|
|
|
} |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, "Max-Age")) { |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, MAX_AGE)) { |
|
|
|
|
cookie.setMaxAge(Integer.parseInt(extractAttributeValue(attribute, setCookieHeader))); |
|
|
|
|
} |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, EXPIRES)) { |
|
|
|
|
@ -155,23 +162,23 @@ public class MockCookie extends Cookie {
@@ -155,23 +162,23 @@ public class MockCookie extends Cookie {
|
|
|
|
|
// ignore invalid date formats
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, "Path")) { |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, PATH)) { |
|
|
|
|
cookie.setPath(extractAttributeValue(attribute, setCookieHeader)); |
|
|
|
|
} |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, "Secure")) { |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, SECURE)) { |
|
|
|
|
cookie.setSecure(true); |
|
|
|
|
} |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, "HttpOnly")) { |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, HTTP_ONLY)) { |
|
|
|
|
cookie.setHttpOnly(true); |
|
|
|
|
} |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, SAME_SITE)) { |
|
|
|
|
cookie.setSameSite(extractAttributeValue(attribute, setCookieHeader)); |
|
|
|
|
} |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, "Comment")) { |
|
|
|
|
else if (StringUtils.startsWithIgnoreCase(attribute, COMMENT)) { |
|
|
|
|
cookie.setComment(extractAttributeValue(attribute, setCookieHeader)); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
cookie.setAttribute(attribute, extractAttributeValue(attribute, setCookieHeader)); |
|
|
|
|
else if (!attribute.isEmpty()) { |
|
|
|
|
cookie.setAttribute(attribute, extractOptionalAttributeValue(attribute, setCookieHeader)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return cookie; |
|
|
|
|
@ -184,6 +191,11 @@ public class MockCookie extends Cookie {
@@ -184,6 +191,11 @@ public class MockCookie extends Cookie {
|
|
|
|
|
return nameAndValue[1]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String extractOptionalAttributeValue(String attribute, String header) { |
|
|
|
|
String[] nameAndValue = attribute.split("="); |
|
|
|
|
return nameAndValue.length == 2 ? nameAndValue[1] : ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void setAttribute(String name, @Nullable String value) { |
|
|
|
|
if (EXPIRES.equalsIgnoreCase(name)) { |
|
|
|
|
@ -197,15 +209,15 @@ public class MockCookie extends Cookie {
@@ -197,15 +209,15 @@ public class MockCookie extends Cookie {
|
|
|
|
|
return new ToStringCreator(this) |
|
|
|
|
.append("name", getName()) |
|
|
|
|
.append("value", getValue()) |
|
|
|
|
.append("Path", getPath()) |
|
|
|
|
.append("Domain", getDomain()) |
|
|
|
|
.append(PATH, getPath()) |
|
|
|
|
.append(DOMAIN, getDomain()) |
|
|
|
|
.append("Version", getVersion()) |
|
|
|
|
.append("Comment", getComment()) |
|
|
|
|
.append("Secure", getSecure()) |
|
|
|
|
.append("HttpOnly", isHttpOnly()) |
|
|
|
|
.append(COMMENT, getComment()) |
|
|
|
|
.append(SECURE, getSecure()) |
|
|
|
|
.append(HTTP_ONLY, isHttpOnly()) |
|
|
|
|
.append(PARTITIONED, isPartitioned()) |
|
|
|
|
.append(SAME_SITE, getSameSite()) |
|
|
|
|
.append("Max-Age", getMaxAge()) |
|
|
|
|
.append(MAX_AGE, getMaxAge()) |
|
|
|
|
.append(EXPIRES, getAttribute(EXPIRES)) |
|
|
|
|
.toString(); |
|
|
|
|
} |
|
|
|
|
|