/** * The modified date response header is used by the client for content caching. It seems obvious * that if we have a modified date on the resource we should set it. BUT, because of the * interaction with max-age we should always set it to the current date if we have max-age The * problem, is that if we find that a condition GET has an expired mod-date (based on maxAge) then * we want to respond with content (even if our mod-date hasnt changed. But if we use the actual * mod-date in that case, then the browser will continue to use the old mod-date, so will forever * more respond with content. So we send a mod-date of now to ensure that future requests will be * given a 304 not modified.* * * @param response * @param resource * @param auth */ public static void setModifiedDate(Response response, Resource resource, Auth auth) { Date modDate = resource.getModifiedDate(); if (modDate != null) { // HACH - see if this helps IE response.setLastModifiedHeader(modDate); // if (resource instanceof GetableResource) { // GetableResource gr = (GetableResource) resource; // Long maxAge = gr.getMaxAgeSeconds(auth); // if (maxAge != null && maxAge > 0) { // log.trace("setModifiedDate: has a modified date and a positive maxAge, // so adjust modDate"); // long tm = System.currentTimeMillis() - 60000; // modified 1 minute ago // modDate = new Date(tm); // have max-age, so use current date // } // } // response.setLastModifiedHeader(modDate); } }
@Override public void respondNotModified(GetableResource resource, Response response, Request request) { log.trace("respondNotModified"); response.setStatus(Response.Status.SC_NOT_MODIFIED); response.setDateHeader(new Date()); String etag = eTagGenerator.generateEtag(resource); if (etag != null) { response.setEtag(etag); } // Note that we use a simpler modified date handling here then when // responding with content, because in a not-modified situation the // modified date MUST be that of the actual resource Date modDate = resource.getModifiedDate(); response.setLastModifiedHeader(modDate); cacheControlHelper.setCacheControl(resource, response, request.getAuthorization()); }