String ifNonMatchValue = context.getHeader("if-none-match");
if (ifNonMatchValue != null) {
String currentETag = Utils.calculateEntityTag(resource);
if (ifNonMatchValue.equals(currentETag)) {
/* the version is not modified */
ResponseContext response = new StringResponseContext("Not Modified", 304);
return new ResponseTarget(context, response);
}
}
// date based conditional get
long ifModifiedSinceValue = 0;
Date ifModifiedSince = context.getDateHeader("If-Modified-Since");
if (ifModifiedSince != null) {
ifModifiedSinceValue = ifModifiedSince.getTime();
}
if (ifModifiedSinceValue > 0) {
long lastModifiedValue = resource.getLastModified().getTime();
// convert the time values from milliseconds to seconds
ifModifiedSinceValue /= 1000;
lastModifiedValue /= 1000;
/* condition to check we have latest updates in terms of dates */
if (ifModifiedSinceValue >= lastModifiedValue) {
/* no need to response with data */
ResponseContext response = new StringResponseContext("Not Modified", 304);
return new ResponseTarget(context, response);
}
}
}
}