private Response.ResponseBuilder evaluateIfMatch(final EntityTag eTag) { final Set<? extends EntityTag> matchingTags = getIfMatch(); if (matchingTags == null) { return null; } // 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-Match header should fail. if (eTag.isWeak()) { return Response.status(Response.Status.PRECONDITION_FAILED); } if (matchingTags != MatchingEntityTag.ANY_MATCH && !matchingTags.contains(eTag)) { // 412 Precondition Failed return Response.status(Response.Status.PRECONDITION_FAILED); } return null; }
private Response.ResponseBuilder evaluateIfMatch(final EntityTag eTag) { final Set<? extends EntityTag> matchingTags = getIfMatch(); if (matchingTags == null) { return null; } // 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-Match header should fail. if (eTag.isWeak()) { return Response.status(Response.Status.PRECONDITION_FAILED); } if (matchingTags != MatchingEntityTag.ANY_MATCH && !matchingTags.contains(eTag)) { // 412 Precondition Failed return Response.status(Response.Status.PRECONDITION_FAILED); } return null; }
@Override public String toString(EntityTag header) { throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.ENTITY_TAG_IS_NULL()); StringBuilder b = new StringBuilder(); if (header.isWeak()) { b.append("W/"); } StringBuilderUtils.appendQuoted(b, header.getValue()); return b.toString(); }
@Override public String toString(EntityTag header) { throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.ENTITY_TAG_IS_NULL()); StringBuilder b = new StringBuilder(); if (header.isWeak()) { b.append("W/"); } StringBuilderUtils.appendQuoted(b, header.getValue()); return b.toString(); }
private Response.ResponseBuilder evaluateIfNoneMatch(final EntityTag eTag, final Set<? extends EntityTag> matchingTags, final 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; }
private Response.ResponseBuilder evaluateIfNoneMatch(final EntityTag eTag, final Set<? extends EntityTag> matchingTags, final 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; }
private ResponseBuilder evaluateIfMatch(EntityTag eTag) { Set<MatchingEntityTag> matchingTags = HttpHelper.getIfMatch(this); if (matchingTags == null) { return null; } // 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-Match header should fail. if (eTag.isWeak()) { return Responses.preconditionFailed(); } if (matchingTags != MatchingEntityTag.ANY_MATCH && !matchingTags.contains(eTag)) { // 412 Precondition Failed return Responses.preconditionFailed(); } return null; }
private ResponseBuilder evaluateIfNoneMatch( EntityTag eTag, Set<MatchingEntityTag> 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 Responses.preconditionFailed(); } } return null; }
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { response.getHttpHeaders().add(HttpHeaders.VARY, HttpHeaders.ACCEPT_ENCODING); // add vary header String acceptEncoding = request.getRequestHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING); String contentEncoding = (String) response.getHttpHeaders().getFirst(HttpHeaders.CONTENT_ENCODING); if (acceptEncoding != null && contentEncoding == null && acceptEncoding.contains("gzip")) { // Check EntityTag header if (response.getHttpHeaders().containsKey(HttpHeaders.ETAG)) { EntityTag entityTag = (EntityTag) response.getHttpHeaders().getFirst(HttpHeaders.ETAG); if (entityTag != null) { response.getHttpHeaders().putSingle(HttpHeaders.ETAG, new EntityTag(entityTag.getValue() + ENTITY_TAG_GZIP_SUFFIX_VALUE, entityTag.isWeak())); } } // wrap entity with gzip if (response.getEntity() != null) { response.getHttpHeaders().add(HttpHeaders.CONTENT_ENCODING, "gzip"); response.setContainerResponseWriter(new Adapter(response.getContainerResponseWriter())); } } return response; } }
public String toString(EntityTag value) { String weak = value.isWeak() ? "W/" : ""; return weak + '"' + value.getValue() + '"'; }
private Response.ResponseBuilder evaluateIfMatch(final EntityTag eTag) { final Set<? extends EntityTag> matchingTags = getIfMatch(); if (matchingTags == null) { return null; } // 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-Match header should fail. if (eTag.isWeak()) { return Response.status(Response.Status.PRECONDITION_FAILED); } if (matchingTags != MatchingEntityTag.ANY_MATCH && !matchingTags.contains(eTag)) { // 412 Precondition Failed return Response.status(Response.Status.PRECONDITION_FAILED); } return null; }
private Response.ResponseBuilder evaluateIfNoneMatch(final EntityTag eTag, final Set<? extends EntityTag> matchingTags, final 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; }
public String toString(EntityTag tag) { StringBuilder sb = new StringBuilder(); if (tag.isWeak()) { sb.append(WEAK_PREFIX); } String tagValue = tag.getValue(); if (!tagValue.startsWith("\"")) { sb.append("\"").append(tagValue).append("\""); } else { sb.append(tagValue); } return sb.toString(); }
public String toString(EntityTag value) { String weak = value.isWeak() ? "W/" : ""; return weak + '"' + value.getValue() + '"'; }
private boolean eTagsStrongEqual(EntityTag etag, EntityTag otherEtag) { // Strong comparison is required. // From specification: // The strong comparison function: in order to be considered equal, // both validators MUST be identical in every way, and both MUST NOT be weak. return !etag.isWeak() && !otherEtag.isWeak() && ("*".equals(otherEtag.getValue()) || etag.getValue().equals(otherEtag.getValue())); }
public String toString(EntityTag header) { StringBuilder b = new StringBuilder(); if (header.isWeak()) b.append("W/"); WriterUtil.appendQuoted(b,header.getValue()); return b.toString(); }
@Override public String toString(EntityTag header) { throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.ENTITY_TAG_IS_NULL()); StringBuilder b = new StringBuilder(); if (header.isWeak()) { b.append("W/"); } StringBuilderUtils.appendQuoted(b, header.getValue()); return b.toString(); }
@Override public String toString(EntityTag header) { throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.ENTITY_TAG_IS_NULL()); StringBuilder b = new StringBuilder(); if (header.isWeak()) { b.append("W/"); } StringBuilderUtils.appendQuoted(b, header.getValue()); return b.toString(); }
@Override public String toString(EntityTag header) { throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.ENTITY_TAG_IS_NULL()); StringBuilder b = new StringBuilder(); if (header.isWeak()) { b.append("W/"); } StringBuilderUtils.appendQuoted(b, header.getValue()); return b.toString(); }
@Override public String toString(EntityTag header) { throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.ENTITY_TAG_IS_NULL()); StringBuilder b = new StringBuilder(); if (header.isWeak()) { b.append("W/"); } StringBuilderUtils.appendQuoted(b, header.getValue()); return b.toString(); }