in httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/LaxExpiresHandler.java [116:190]
public void parse(final SetCookie cookie, final String value) throws MalformedCookieException {
Args.notNull(cookie, "Cookie");
if (TextUtils.isBlank(value)) {
return;
}
final Tokenizer.Cursor cursor = new Tokenizer.Cursor(0, value.length());
final StringBuilder content = new StringBuilder();
int second = 0, minute = 0, hour = 0, day = 0, year = 0;
Month month = Month.JANUARY;
boolean foundTime = false, foundDayOfMonth = false, foundMonth = false, foundYear = false;
try {
while (!cursor.atEnd()) {
skipDelims(value, cursor);
content.setLength(0);
copyContent(value, cursor, content);
if (content.length() == 0) {
break;
}
if (!foundTime) {
final Matcher matcher = TIME_PATTERN.matcher(content);
if (matcher.matches()) {
foundTime = true;
hour = Integer.parseInt(matcher.group(1));
minute = Integer.parseInt(matcher.group(2));
second = Integer.parseInt(matcher.group(3));
continue;
}
}
if (!foundDayOfMonth) {
final Matcher matcher = DAY_OF_MONTH_PATTERN.matcher(content);
if (matcher.matches()) {
foundDayOfMonth = true;
day = Integer.parseInt(matcher.group(1));
continue;
}
}
if (!foundMonth) {
final Matcher matcher = MONTH_PATTERN.matcher(content);
if (matcher.matches()) {
foundMonth = true;
month = MONTHS.get(matcher.group(1).toLowerCase(Locale.ROOT));
continue;
}
}
if (!foundYear) {
final Matcher matcher = YEAR_PATTERN.matcher(content);
if (matcher.matches()) {
foundYear = true;
year = Integer.parseInt(matcher.group(1));
continue;
}
}
}
} catch (final NumberFormatException ignore) {
throw new MalformedCookieException("Invalid 'expires' attribute: " + value);
}
if (!foundTime || !foundDayOfMonth || !foundMonth || !foundYear) {
throw new MalformedCookieException("Invalid 'expires' attribute: " + value);
}
if (year >= 70 && year <= 99) {
year = 1900 + year;
}
if (year >= 0 && year <= 69) {
year = 2000 + year;
}
if (day < 1 || day > 31 || year < 1601 || hour > 23 || minute > 59 || second > 59) {
throw new MalformedCookieException("Invalid 'expires' attribute: " + value);
}
final Instant expiryDate = ZonedDateTime.of(year, month.getValue(), day, hour, minute, second, 0,
ZoneId.of("UTC")).toInstant();
cookie.setExpiryDate(expiryDate);
}