You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2012/07/14 21:03:55 UTC

svn commit: r1361574 - /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java

Author: pmouawad
Date: Sat Jul 14 19:03:54 2012
New Revision: 1361574

URL: http://svn.apache.org/viewvc?rev=1361574&view=rev
Log:
Bug 53522 - Cache Manager should not store at all response with header "no-cache" and store other types of Cache-Control having max-age value
IF Last-Modified or Date are missing or invalid, set expiration date to one year in future
Bugzilla Id: 53522

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java?rev=1361574&r1=1361573&r2=1361574&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java Sat Jul 14 19:03:54 2012
@@ -66,7 +66,7 @@ public class CacheManager extends Config
 
     private static final int DEFAULT_MAX_SIZE = 5000;
 
-    private static final long TWO_WEEKS_MS = 15*86400*1000;
+    private static final long ONE_YEAR_MS = 365*86400*1000;
 
     public CacheManager() {
         setProperty(new BooleanProperty(CLEAR, false));
@@ -195,7 +195,7 @@ public class CacheManager extends Config
                     expiresDate=new Date(System.currentTimeMillis()+maxAgeInSecs*1000);
 
                 } else if(expires==null) { // No max-age && No expires
-                    if(!StringUtils.isEmpty(lastModified)) {
+                    if(!StringUtils.isEmpty(lastModified) && !StringUtils.isEmpty(date)) {
                         try {
                             Date responseDate = DateUtil.parseDate( date );
                             Date lastModifiedAsDate = DateUtil.parseDate( lastModified );
@@ -203,10 +203,23 @@ public class CacheManager extends Config
                             // see http://www.ietf.org/rfc/rfc2616.txt#13.2.4 
                             expiresDate=new Date(System.currentTimeMillis()
                                     +Math.round((responseDate.getTime()-lastModifiedAsDate.getTime())*0.1));
-                        } catch (DateParseException e) {
-                            // Not sure here
-                            expiresDate = new Date(0L); // invalid dates must be treated as expired
+                        } catch(DateParseException e) {
+                            // date or lastModified may be null or in bad format
+                            if(log.isWarnEnabled()) {
+                                log.warn("Failed computing expiration date with following info:"
+                                    +lastModified + "," 
+                                    + cacheControl + ","
+                                    + expires + "," 
+                                    + etag + ","
+                                    + url + ","
+                                    + date);
+                            }
+                            // TODO Can't see anything in SPEC
+                            expiresDate = new Date(System.currentTimeMillis()+ONE_YEAR_MS);                      
                         }
+                    } else {
+                        // TODO Can't see anything in SPEC
+                        expiresDate = new Date(System.currentTimeMillis()+ONE_YEAR_MS);                      
                     }
                 }  
                 // else expiresDate computed in (expires!=null) condition is used