public boolean isServableFromCache(final HttpRequest request){
final String method = request.getRequestLine().getMethod();
final protocolVersion pv = request.getRequestLine().getProtocolVersion();
if(HttpVersion.HTTP_1_1.compareToVersion(pv) != 0){
return false;
}
if(!(method.equals(HeaderConstants.GET_METHOD))||method.equals(HeaderConstants.HEAD_METHOD)){
return false;
}
if(request.getHeaders(HeaderConstants.PRAGMA).length>0){
return false;
}
final Header[] cacheControlHeaders = request.getHeaders(HeaderConstants.CACHE_CONTROL);
for(final Header cacheControl:cacheControlHeaders){
for(final HeaderELement cacheControlElement : cacheControl.getElements()){
if("no-store".equalsIgnoreCase(cacheControlElement.getName())){
return false;
}
if("no-cache".equals(cacheControlElement.getName())){
return false;
}
}
}
return true;
}
|