You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2012/04/06 11:16:38 UTC

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

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);
+    }
    
 }