CachedHttpRequest existingKey = (CachedHttpRequest) entry.key();
//if any of the header matches fail we just return
//we don't can the request, as it is possible the underlying handler
//may have additional etags
final ETag etag = existingKey.getEtag();
if (!ETagUtils.handleIfMatch(exchange, etag, false)) {
return false;
}
//we do send a 304 if the if-none-match header matches
if (!ETagUtils.handleIfNoneMatch(exchange, etag, true)) {
exchange.setResponseCode(304);
exchange.endExchange();
return true;
}
//the server may have a more up to date representation
if (!DateUtils.handleIfUnmodifiedSince(exchange, existingKey.getLastModified())) {
return false;
}
if (!DateUtils.handleIfModifiedSince(exchange, existingKey.getLastModified())) {
exchange.setResponseCode(304);
exchange.endExchange();
return true;
}
//we are going to proceed. Set the appropriate headers
if(existingKey.getContentType() != null) {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, existingKey.getContentType());
}
if(existingKey.getContentEncoding() != null && !Headers.IDENTITY.equals(HttpString.tryFromString(existingKey.getContentEncoding()))) {
exchange.getResponseHeaders().put(Headers.CONTENT_ENCODING, existingKey.getContentEncoding());
}
if(existingKey.getLastModified() != null) {
exchange.getResponseHeaders().put(Headers.LAST_MODIFIED, DateUtils.toDateString(existingKey.getLastModified()));
}
if(existingKey.getContentLocation() != null) {
exchange.getResponseHeaders().put(Headers.CONTENT_LOCATION, existingKey.getContentLocation());
}
if(existingKey.getLanguage() != null) {
exchange.getResponseHeaders().put(Headers.CONTENT_LANGUAGE, existingKey.getLanguage());
}
if(etag != null) {
exchange.getResponseHeaders().put(Headers.CONTENT_LANGUAGE, etag.toString());
}
//TODO: support if-range
exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, Long.toString(entry.size()));
if (exchange.getRequestMethod().equals(HEAD)) {