Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ private String getCookieHeader(Cookie cookie) {
buf.append("; Domain=").append(cookie.getDomain());
}
int maxAge = cookie.getMaxAge();
ZonedDateTime expires = (cookie instanceof MockCookie ? ((MockCookie) cookie).getExpires() : null);
if (maxAge >= 0) {
buf.append("; Max-Age=").append(maxAge);
buf.append("; Expires=");
ZonedDateTime expires = (cookie instanceof MockCookie ? ((MockCookie) cookie).getExpires() : null);
if (expires != null) {
buf.append(expires.format(DateTimeFormatter.RFC_1123_DATE_TIME));
}
Expand All @@ -387,6 +387,11 @@ private String getCookieHeader(Cookie cookie) {
buf.append(headers.getFirst(HttpHeaders.EXPIRES));
}
}
else if (expires != null) {
buf.append("; Expires=");
buf.append(expires.format(DateTimeFormatter.RFC_1123_DATE_TIME));
}


if (cookie.getSecure()) {
buf.append("; Secure");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ void addCookieHeaderWithZeroExpiresAttribute() {
assertThat(header).startsWith("SESSION=123; Path=/; Max-Age=100; Expires=");
}

/**
* @since 5.1.12
*/
@Test
void addCookieHeaderWithOnlyExpiresAttribute() {
String cookieValue = "SESSION=123; Path=/; Expires=Tue, 8 Oct 2019 19:50:00 GMT";
response.addHeader(SET_COOKIE, cookieValue);
assertNumCookies(1);
assertThat(response.getHeader(SET_COOKIE)).isEqualTo(cookieValue);
}

@Test
void addCookie() {
MockCookie mockCookie = new MockCookie("SESSION", "123");
Expand Down