/** * Returns the last value corresponding to the specified field parsed as an HTTP date, or null if * either the field is absent or cannot be parsed as a date. */ public @Nullable Date getDate(String name) { String value = get(name); return value != null ? HttpDate.parse(value) : null; }
/** * Set a field with the specified date. If the field is not found, it is added. If the field is * found, the existing values are replaced. */ public Builder set(String name, Date value) { if (value == null) throw new NullPointerException("value for name " + name + " == null"); set(name, HttpDate.format(value)); return this; }
/** * Returns the last value corresponding to the specified field parsed as an HTTP date, or null if * either the field is absent or cannot be parsed as a date. */ public @Nullable Date getDate(String name) { String value = get(name); return value != null ? HttpDate.parse(value) : null; }
/** * Add a header with the specified name and formatted date. Does validation of header names and * value. */ public Builder add(String name, Date value) { if (value == null) throw new NullPointerException("value for name " + name + " == null"); add(name, HttpDate.format(value)); return this; }
public Factory(long nowMillis, Request request, Response cacheResponse) { this.nowMillis = nowMillis; this.request = request; this.cacheResponse = cacheResponse; if (cacheResponse != null) { this.sentRequestMillis = cacheResponse.sentRequestAtMillis(); this.receivedResponseMillis = cacheResponse.receivedResponseAtMillis(); Headers headers = cacheResponse.headers(); for (int i = 0, size = headers.size(); i < size; i++) { String fieldName = headers.name(i); String value = headers.value(i); if ("Date".equalsIgnoreCase(fieldName)) { servedDate = HttpDate.parse(value); servedDateString = value; } else if ("Expires".equalsIgnoreCase(fieldName)) { expires = HttpDate.parse(value); } else if ("Last-Modified".equalsIgnoreCase(fieldName)) { lastModified = HttpDate.parse(value); lastModifiedString = value; } else if ("ETag".equalsIgnoreCase(fieldName)) { etag = value; } else if ("Age".equalsIgnoreCase(fieldName)) { ageSeconds = HttpHeaders.parseSeconds(value, -1); } } } }
result.append("; max-age=0"); } else { result.append("; expires=").append(HttpDate.format(new Date(expiresAt)));
static boolean isStale(Request request, Response response) { String timeoutStr = request.header(CACHE_EXPIRE_TIMEOUT_HEADER); String servedDateStr = response.header(CACHE_SERVED_DATE_HEADER); if (servedDateStr == null || timeoutStr == null) { return true; } long timeout = Long.parseLong(timeoutStr); if (timeout == 0) { return false; } Date servedDate = HttpDate.parse(servedDateStr); long now = System.currentTimeMillis(); return servedDate == null || now - servedDate.getTime() > timeout; }
/** * Add a header with the specified name and formatted date. Does validation of header names and * value. */ public Builder add(String name, Date value) { if (value == null) throw new NullPointerException("value for name " + name + " == null"); add(name, HttpDate.format(value)); return this; }
public Factory(long nowMillis, Request request, Response cacheResponse) { this.nowMillis = nowMillis; this.request = request; this.cacheResponse = cacheResponse; if (cacheResponse != null) { this.sentRequestMillis = cacheResponse.sentRequestAtMillis(); this.receivedResponseMillis = cacheResponse.receivedResponseAtMillis(); Headers headers = cacheResponse.headers(); for (int i = 0, size = headers.size(); i < size; i++) { String fieldName = headers.name(i); String value = headers.value(i); if ("Date".equalsIgnoreCase(fieldName)) { servedDate = HttpDate.parse(value); servedDateString = value; } else if ("Expires".equalsIgnoreCase(fieldName)) { expires = HttpDate.parse(value); } else if ("Last-Modified".equalsIgnoreCase(fieldName)) { lastModified = HttpDate.parse(value); lastModifiedString = value; } else if ("ETag".equalsIgnoreCase(fieldName)) { etag = value; } else if ("Age".equalsIgnoreCase(fieldName)) { ageSeconds = HttpHeaders.parseSeconds(value, -1); } } } }
/** * Set a field with the specified date. If the field is not found, it is added. If the field is * found, the existing values are replaced. */ public Builder set(String name, Date value) { if (value == null) throw new NullPointerException("value for name " + name + " == null"); set(name, HttpDate.format(value)); return this; }
/** * Returns the last value corresponding to the specified field parsed as an * HTTP date, or null if either the field is absent or cannot be parsed as a * date. */ public Date getDate(String name) { String value = get(name); return value != null ? HttpDate.parse(value) : null; }
@Override public void setIfModifiedSince(long newValue) { super.setIfModifiedSince(newValue); if (ifModifiedSince != 0) { requestHeaders.set("If-Modified-Since", HttpDate.format(new Date(ifModifiedSince))); } else { requestHeaders.removeAll("If-Modified-Since"); } }
/** * Returns the last value corresponding to the specified field parsed as an HTTP date, or null if * either the field is absent or cannot be parsed as a date. */ public Date getDate(String name) { String value = get(name); return value != null ? HttpDate.parse(value) : null; }
static Response withServedDateHeader(Response response) throws IOException { return response.newBuilder() .addHeader(CACHE_SERVED_DATE_HEADER, HttpDate.format(new Date())) .build(); }
/** * Returns the last value corresponding to the specified field parsed as an HTTP date, or null if * either the field is absent or cannot be parsed as a date. */ public @Nullable Date getDate(String name) { String value = get(name); return value != null ? HttpDate.parse(value) : null; }
result.append("; max-age=0"); } else { result.append("; expires=").append(HttpDate.format(new Date(expiresAt)));
/** * Returns the last value corresponding to the specified field parsed as an * HTTP date, or null if either the field is absent or cannot be parsed as a * date. */ public Date getDate(String name) { String value = get(name); return value != null ? HttpDate.parse(value) : null; }
/** * Add a header with the specified name and formatted Date. * Does validation of header names and values. */ public Builder add(String name, Date value) { if (value == null) throw new NullPointerException("value for name " + name + " == null"); add(name, HttpDate.format(value)); return this; }
/** * Returns the last value corresponding to the specified field parsed as an HTTP date, or null if * either the field is absent or cannot be parsed as a date. */ public @Nullable Date getDate(String name) { String value = get(name); return value != null ? HttpDate.parse(value) : null; }
/** * Set a field with the specified date. If the field is not found, it is added. If the field is * found, the existing values are replaced. */ public Builder set(String name, Date value) { if (value == null) throw new NullPointerException("value for name " + name + " == null"); set(name, HttpDate.format(value)); return this; }