jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1361555 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java xdocs/usermanual/component_reference.xml
Date Sat, 14 Jul 2012 15:49:16 GMT
Author: pmouawad
Date: Sat Jul 14 15:49:16 2012
New Revision: 1361555

URL: http://svn.apache.org/viewvc?rev=1361555&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
Added test case
Added sleep to ensure entries become invalid after their expiration date has passed
Bugzilla Id: 53522

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java
    jmeter/trunk/xdocs/usermanual/component_reference.xml

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=1361555&r1=1361554&r2=1361555&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 15:49:16 2012
@@ -33,6 +33,7 @@ import org.apache.commons.httpclient.Htt
 import org.apache.commons.httpclient.URIException;
 import org.apache.commons.httpclient.util.DateParseException;
 import org.apache.commons.httpclient.util.DateUtil;
+import org.apache.commons.lang.StringUtils;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.jmeter.config.ConfigTestElement;
@@ -116,7 +117,8 @@ public class CacheManager extends Config
             String etag = conn.getHeaderField(HTTPConstants.ETAG);
             String url = conn.getURL().toString();
             String cacheControl = conn.getHeaderField(HTTPConstants.CACHE_CONTROL);
-            setCache(lastModified, cacheControl, expires, etag, url);
+            String date = conn.getHeaderField(HTTPConstants.DATE);
+            setCache(lastModified, cacheControl, expires, etag, url, date);
         }
     }
 
@@ -133,7 +135,8 @@ public class CacheManager extends Config
             String etag = getHeader(method ,HTTPConstants.ETAG);
             String url = method.getURI().toString();
             String cacheControl = getHeader(method, HTTPConstants.CACHE_CONTROL);
-            setCache(lastModified, cacheControl, expires, etag, url);
+            String date = getHeader(method, HTTPConstants.DATE);
+            setCache(lastModified, cacheControl, expires, etag, url, date);
         }
     }
 
@@ -150,12 +153,13 @@ public class CacheManager extends Config
             String expires = getHeader(method ,HTTPConstants.EXPIRES);
             String etag = getHeader(method ,HTTPConstants.ETAG);
             String cacheControl = getHeader(method, HTTPConstants.CACHE_CONTROL);
-            setCache(lastModified, cacheControl, expires, etag, res.getUrlAsString()); //
TODO correct URL?
+            String date = getHeader(method, HTTPConstants.DATE);
+            setCache(lastModified, cacheControl, expires, etag, res.getUrlAsString(), date);
// TODO correct URL?
         }
     }
 
     // helper method to save the cache entry
-    private void setCache(String lastModified, String cacheControl, String expires, String
etag, String url) {
+    private void setCache(String lastModified, String cacheControl, String expires, String
etag, String url, String date) {
         if (log.isDebugEnabled()){
             log.debug("SET(both) "+url + " " + cacheControl + " " + lastModified + " " +
" " + expires + " " + etag);
         }
@@ -186,7 +190,19 @@ public class CacheManager extends Config
                 // No max-age && No expires => store forever
                 else if(expires==null) {
                     // No max-age
-                    expiresDate=new Date(System.currentTimeMillis()+TWO_WEEKS_MS);
+                    if(!StringUtils.isEmpty(lastModified)) {
+                        try {
+                            Date responseDate = DateUtil.parseDate( date );
+                            Date lastModifiedAsDate = DateUtil.parseDate( lastModified );
+                            // see https://developer.mozilla.org/en/HTTP_Caching_FAQ
+                            // 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
+                        }
+                    }
                 }  
                 // else expiresDate computed in (expires!=null) condition is used
             }

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java?rev=1361555&r1=1361554&r2=1361555&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java
Sat Jul 14 15:49:16 2012
@@ -64,5 +64,6 @@ public interface HTTPConstantsInterface 
     public static final String LAST_MODIFIED = "Last-Modified"; // $NON-NLS-1$
     public static final String EXPIRES = "Expires"; // $NON-NLS-1$
     public static final String CACHE_CONTROL = "Cache-Control";  //e.g. public, max-age=259200
+    public static final String DATE = "Date";  //e.g. Date Header of response 
 
 }

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1361555&r1=1361554&r2=1361555&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sat Jul 14 15:49:16 2012
@@ -3226,7 +3226,8 @@ Additionally, if the "Use Cache-Control/
 If the request is a GET request, and the timestamp is in the future, then the sampler returns
immediately,
 without requesting the URL from the remote server. This is intended to emulate browser behaviour.
 Note that if Cache-Control header is "no-cache", response will not be stored in cache, if
Cache-Control has any other value, 
-the "max-age" expiry option is processed to compute entry lifetime, if missing then expire
header will be used, if also missing entry will be cached forever (2 weeks).
+the "max-age" expiry option is processed to compute entry lifetime, if missing then expire
header will be used, if also missing entry will be cached 
+as sas specified in <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a>
section 13.2.4. 
 </p>
 <p>
 By default, Cache Manager will store up to 5000 items in cache using LRU algorithm. Use property
to modify this value.



Mime
View raw message