String ifNoneMatch = getRequestHeaders().getFirst(IF_NONE_MATCH);
if (ifNoneMatch == null)
return null;
EntityTag otherEtag = EntityTag.valueOf(ifNoneMatch);
String httpMethod = getMethod();
// The weak comparison function can only be used with GET or HEAD requests.
if (httpMethod.equals(HttpMethod.GET) || httpMethod.equals(HttpMethod.HEAD))
{
if ("*".equals(otherEtag.getValue()) || etag.getValue().equals(otherEtag.getValue()))
return Response.notModified(etag);
}
else
{
// Use strong comparison (ignore weak tags) because HTTP method is not GET
// or HEAD. If one of tag is weak then tags are not identical.
if (!etag.isWeak() && !otherEtag.isWeak()
&& ("*".equals(otherEtag.getValue()) || etag.getValue().equals(otherEtag.getValue())))
return Response.status(Response.Status.PRECONDITION_FAILED);
}
// if tags are matched then do as tag 'if-none-match' is absent