Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 873079179 for ; Fri, 6 Apr 2012 09:17:02 +0000 (UTC) Received: (qmail 203 invoked by uid 500); 6 Apr 2012 09:17:01 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 99989 invoked by uid 500); 6 Apr 2012 09:17:01 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 99968 invoked by uid 99); 6 Apr 2012 09:17:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Apr 2012 09:17:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Apr 2012 09:16:59 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1E6C02388865; Fri, 6 Apr 2012 09:16:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1310252 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java Date: Fri, 06 Apr 2012 09:16:38 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120406091639.1E6C02388865@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergeyb Date: Fri Apr 6 09:16:38 2012 New Revision: 1310252 URL: http://svn.apache.org/viewvc?rev=1310252&view=rev Log: [CXF-4231] Handling If-None-Match and If-Modified-Since pair as recommended by HTTP spec, patch from Jan Engehausen applied with thanks Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java?rev=1310252&r1=1310251&r2=1310252&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java Fri Apr 6 09:16:38 2012 @@ -205,12 +205,16 @@ public class RequestImpl implements Requ public ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) { - ResponseBuilder rb = evaluatePreconditions(eTag); + final ResponseBuilder rb = evaluatePreconditions(eTag); if (rb != null) { - return rb; + // the ETag conditions match; so now conditions for last modified must match + return evaluatePreconditions(lastModified); + } else { + // the ETag conditions do not match, so last modified should be ignored + // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html (section 14.26 for + // "If-None-Match", behavior not specified for "If-Match", section 14.24) + return null; } - return evaluatePreconditions(lastModified); - } public String getMethod() { Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java?rev=1310252&r1=1310251&r2=1310252&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java Fri Apr 6 09:16:38 2012 @@ -268,5 +268,34 @@ public class RequestImplTest extends Ass Response r = rb.build(); assertEquals("If-Modified-Since precondition was not met", 304, r.getStatus()); } + + @Test + public void testIfNoneMatchAndDateWithMatchingTags() throws Exception { + metadata.putSingle(HttpHeaders.IF_NONE_MATCH, "\"123\""); + metadata.putSingle("If-Modified-Since", "Tue, 21 Oct 2008 14:00:00 GMT"); + + Date lastModified = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH) + .parse("Mon, 20 Oct 2008 14:00:00 GMT"); + + ResponseBuilder rb = + new RequestImpl(m).evaluatePreconditions(lastModified, new EntityTag("123")); + assertNotNull("Precondition is not met", rb); + + Response r = rb.build(); + assertEquals("If-Modified-Since precondition was not met", 304, r.getStatus()); + } + + @Test + public void testIfNoneMatchAndDateWithNonMatchingTags() throws Exception { + metadata.putSingle(HttpHeaders.IF_NONE_MATCH, "\"123\""); + metadata.putSingle("If-Modified-Since", "Tue, 21 Oct 2008 14:00:00 GMT"); + + Date lastModified = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH) + .parse("Mon, 20 Oct 2008 14:00:00 GMT"); + + ResponseBuilder rb = + new RequestImpl(m).evaluatePreconditions(lastModified, new EntityTag("124")); + assertNull("Dates must not be checked if tags do not match", rb); + } }