public LocalDateTime getDate() { return headers.getDate().orElse(null); }
public static long getTTL(HTTPResponse response, int defaultTTLinSeconds) { final Optional<CacheControl> cc = response.getHeaders().getCacheControl(); if (cc.isPresent()) { int maxAge = cc.get().getMaxAge(); if (maxAge > 0) { return maxAge; } } /** * HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past (i.e., "already expired"). * To mark a response as "already expired," an origin server sends an Expires date that is equal to the Date header value. * (See the rules for expiration calculations in section 13.2.4.) * To mark a response as "never expires," an origin server sends an Expires date approximately one year from the time the response is sent. * HTTP/1.1 servers SHOULD NOT send Expires dates more than one year in the future. */ Optional<LocalDateTime> expires = response.getHeaders().getExpires(); if (expires.isPresent()) { LocalDateTime expiryDate = expires.get(); Optional<LocalDateTime> date = response.getHeaders().getDate(); if (OptionalUtils.exists(date, dt -> dt.isBefore(expiryDate))) { return Duration.between(date.get(), expiryDate).getSeconds(); } } return defaultTTLinSeconds; }
Optional<LocalDateTime> date = headers.getDate(); if (!expires.isPresent() || !date.isPresent()) { return false;