Skip to content
Merged
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 @@ -69,9 +69,10 @@ public void parse(final SetCookie cookie, final String value)
throw new MalformedCookieException ("Invalid 'max-age' attribute: "
+ value);
}
if (age < 0) {
throw new MalformedCookieException ("Negative 'max-age' attribute: "
+ value);
if (age <= 0) {
// RFC 6265 user-agent processing: delta-seconds <= 0 means immediate expiry.
cookie.setExpiryDate(Instant.EPOCH);
return;
}
cookie.setExpiryDate(Instant.now().plusSeconds(age));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ void testBasicMaxAgeParse() throws Exception {
Assertions.assertNotNull(cookie.getExpiryInstant());
}

@Test
void testBasicMaxAgeParseDeleteNow() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieAttributeHandler h = BasicMaxAgeHandler.INSTANCE;
h.parse(cookie, "0");
Assertions.assertEquals(Instant.EPOCH, cookie.getExpiryInstant());
final BasicClientCookie cookie2 = new BasicClientCookie("name", "value");
h.parse(cookie2, "-1");
Assertions.assertEquals(Instant.EPOCH, cookie2.getExpiryInstant());
}

@Test
void testBasicMaxAgeParseInvalid() {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
Expand Down
Loading