private int mergeMaxAgeAndExpire(int maxAge, String expires) { // max age has precedence over expires if (maxAge != Integer.MIN_VALUE) { return maxAge; } else if (expires != null) { Date expiresDate = HttpHeaderDateFormat.get().parse(expires, new ParsePosition(0)); if (expiresDate != null) { long maxAgeMillis = expiresDate.getTime() - System.currentTimeMillis(); return (int) (maxAgeMillis / 1000 + (maxAgeMillis % 1000 != 0 ? 1 : 0)); } } return Integer.MIN_VALUE; }
/** * Returns the date header value with the specified header name. If * there are more than one header value for the specified header name, the * first value is returned. * * @return the header value * @throws ParseException * if there is no such header or the header value is not a formatted date */ public static Date getDateHeader(HttpMessage message, String name) throws ParseException { String value = getHeader(message, name); if (value == null) { throw new ParseException("header not found: " + name, 0); } return HttpHeaderDateFormat.get().parse(value); }
/** * Returns the date header value with the specified header name. If * there are more than one header value for the specified header name, the * first value is returned. * * @return the header value or the {@code defaultValue} if there is no such * header or the header value is not a formatted date */ public static Date getDateHeader(HttpMessage message, String name, Date defaultValue) { final String value = getHeader(message, name); if (value == null) { return defaultValue; } try { return HttpHeaderDateFormat.get().parse(value); } catch (ParseException e) { // Not a date header - use the default. return defaultValue; } }
try { long maxAgeMillis = HttpHeaderDateFormat.get().parse(value).getTime() - System.currentTimeMillis();