private Response.ResponseBuilder evaluateIfNoneMatch( EntityTag eTag, Set<? extends EntityTag> matchingTags, boolean isGetOrHead) { if (isGetOrHead) { if (matchingTags == MatchingEntityTag.ANY_MATCH) { // 304 Not modified return Response.notModified(eTag); } // The weak comparison function may be used to compare entity tags if (matchingTags.contains(eTag) || matchingTags.contains(new EntityTag(eTag.getValue(), !eTag.isWeak()))) { // 304 Not modified return Response.notModified(eTag); } } else { // The strong comparison function must be used to compare the entity // tags. Thus if the entity tag of the entity is weak then matching // of entity tags in the If-None-Match header should fail if the // HTTP method is not GET or not HEAD. if (eTag.isWeak()) { return null; } if (matchingTags == MatchingEntityTag.ANY_MATCH || matchingTags.contains(eTag)) { // 412 Precondition Failed return Response.status(Response.Status.PRECONDITION_FAILED); } } return null; }
/** * Add ETag and Last-Modified cache control headers to the response * * @param servletResponse the servlet response * @param resource the fedora resource * @param session the session */ protected static void addCacheControlHeaders( final HttpServletResponse servletResponse, final FedoraResource resource, final Session session) { final String txId = TransactionServiceImpl.getCurrentTransactionId(session); if (txId != null) { // Do not add caching headers if in a transaction return; } final FedoraResource mutableResource = resource instanceof NonRdfSourceDescription ? ((NonRdfSourceDescription) resource).getDescribedResource() : resource; final EntityTag etag = new EntityTag(mutableResource.getEtagValue()); final Date date = mutableResource.getLastModifiedDate(); if (!etag.getValue().isEmpty()) { servletResponse.addHeader("ETag", etag.toString()); } if (date != null) { servletResponse.addDateHeader("Last-Modified", date.getTime()); } }