You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2015/07/12 18:25:09 UTC
svn commit: r1690478 - in /jmeter/trunk:
src/protocol/http/org/apache/jmeter/protocol/http/control/
src/protocol/http/org/apache/jmeter/protocol/http/util/
test/src/org/apache/jmeter/protocol/http/control/ xdocs/ xdocs/usermanual/
Author: fschumacher
Date: Sun Jul 12 16:25:08 2015
New Revision: 1690478
URL: http://svn.apache.org/r1690478
Log:
Do not cache http samples that have a Vary header.
Bugzilla Id: 58079
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/test/src/org/apache/jmeter/protocol/http/control/TestCacheManager.java
jmeter/trunk/xdocs/changes.xml
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=1690478&r1=1690477&r2=1690478&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 Sun Jul 12 16:25:08 2015
@@ -122,7 +122,7 @@ public class CacheManager extends Config
* @param res result
*/
public void saveDetails(URLConnection conn, HTTPSampleResult res){
- if (isCacheable(res)){
+ if (isCacheable(res) && !hasVaryHeader(conn)){
String lastModified = conn.getHeaderField(HTTPConstants.LAST_MODIFIED);
String expires = conn.getHeaderField(HTTPConstants.EXPIRES);
String etag = conn.getHeaderField(HTTPConstants.ETAG);
@@ -133,6 +133,10 @@ public class CacheManager extends Config
}
}
+ private boolean hasVaryHeader(URLConnection conn) {
+ return conn.getHeaderField(HTTPConstants.VARY) != null;
+ }
+
/**
* Save the Last-Modified, Etag, and Expires headers if the result is
* cacheable. Version for Commons HttpClient implementation.
@@ -145,7 +149,7 @@ public class CacheManager extends Config
* if extraction of the the uri from <code>method</code> fails
*/
public void saveDetails(HttpMethod method, HTTPSampleResult res) throws URIException{
- if (isCacheable(res)){
+ if (isCacheable(res) && !hasVaryHeader(method)){
String lastModified = getHeader(method ,HTTPConstants.LAST_MODIFIED);
String expires = getHeader(method ,HTTPConstants.EXPIRES);
String etag = getHeader(method ,HTTPConstants.ETAG);
@@ -156,6 +160,10 @@ public class CacheManager extends Config
}
}
+ private boolean hasVaryHeader(HttpMethod method) {
+ return getHeader(method, HTTPConstants.VARY) != null;
+ }
+
/**
* Save the Last-Modified, Etag, and Expires headers if the result is
* cacheable. Version for Apache HttpClient implementation.
@@ -166,7 +174,7 @@ public class CacheManager extends Config
* result to decide if result is cacheable
*/
public void saveDetails(HttpResponse method, HTTPSampleResult res) {
- if (isCacheable(res)){
+ if (isCacheable(res) && !hasVaryHeader(method)){
String lastModified = getHeader(method ,HTTPConstants.LAST_MODIFIED);
String expires = getHeader(method ,HTTPConstants.EXPIRES);
String etag = getHeader(method ,HTTPConstants.ETAG);
@@ -176,6 +184,10 @@ public class CacheManager extends Config
}
}
+ private boolean hasVaryHeader(HttpResponse method) {
+ return getHeader(method, HTTPConstants.VARY) != null;
+ }
+
// helper method to save the cache entry
private void setCache(String lastModified, String cacheControl, String expires, String etag, String url, String date) {
if (log.isDebugEnabled()){
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=1690478&r1=1690477&r2=1690478&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 Sun Jul 12 16:25:08 2015
@@ -75,6 +75,7 @@ public interface HTTPConstantsInterface
String LAST_MODIFIED = "Last-Modified"; // $NON-NLS-1$
String EXPIRES = "Expires"; // $NON-NLS-1$
String CACHE_CONTROL = "Cache-Control"; //e.g. public, max-age=259200
- String DATE = "Date"; //e.g. Date Header of response
+ String DATE = "Date"; //e.g. Date Header of response
+ String VARY = "Vary"; // $NON-NLS-1$
}
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestCacheManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestCacheManager.java?rev=1690478&r1=1690477&r2=1690478&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestCacheManager.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/control/TestCacheManager.java Sun Jul 12 16:25:08 2015
@@ -73,6 +73,8 @@ public class TestCacheManager extends JM
return cacheControl;
} else if (HTTPConstants.DATE.equals(name)){
return currentTimeInGMT;
+ } else if (HTTPConstants.VARY.equals(name)) {
+ return vary;
}
return super.getHeaderField(name);
}
@@ -105,8 +107,10 @@ public class TestCacheManager extends JM
return expires == null ? null : new Header(HTTPConstants.EXPIRES, expires);
} else if (HTTPConstants.CACHE_CONTROL.equals(headerName)) {
return cacheControl == null ? null : new Header(HTTPConstants.CACHE_CONTROL, cacheControl);
- } if (HTTPConstants.DATE.equals(headerName)) {
+ } else if (HTTPConstants.DATE.equals(headerName)) {
return this.dateHeader;
+ } else if (HTTPConstants.VARY.equals(headerName)) {
+ return vary == null ? null : new Header(HTTPConstants.VARY, vary);
}
return null;
}
@@ -144,6 +148,7 @@ public class TestCacheManager extends JM
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
private CacheManager cacheManager;
private String currentTimeInGMT;
+ private String vary = null;
private URL url;
private URI uri;
private URLConnection urlConnection;
@@ -228,6 +233,20 @@ public class TestCacheManager extends JM
assertFalse("Should not find valid entry",this.cacheManager.inCache(url));
}
+ public void testCacheVaryJava() throws Exception{
+ this.cacheManager.setUseExpires(true);
+ this.cacheManager.testIterationStart(null);
+ assertNull("Should not find entry",getThreadCacheEntry(LOCAL_HOST));
+ assertFalse("Should not find valid entry",this.cacheManager.inCache(url));
+ ((URLConnectionStub)urlConnection).expires=makeDate(new Date(System.currentTimeMillis()));
+ ((URLConnectionStub)urlConnection).cacheControl="public, max-age=5";
+ this.vary="Accept-Encoding";
+ this.cacheManager.saveDetails(this.urlConnection, sampleResultOK);
+ this.vary=null;
+ assertNull("Should not find entry",getThreadCacheEntry(LOCAL_HOST));
+ assertFalse("Should not find valid entry",this.cacheManager.inCache(url));
+ }
+
public void testExpiresHttpClient() throws Exception{
this.cacheManager.setUseExpires(true);
this.cacheManager.testIterationStart(null);
@@ -257,7 +276,21 @@ public class TestCacheManager extends JM
assertNotNull("Should find entry",getThreadCacheEntry(LOCAL_HOST));
assertFalse("Should not find valid entry",this.cacheManager.inCache(url));
}
-
+
+ public void testCacheVaryHttpClient() throws Exception{
+ this.cacheManager.setUseExpires(true);
+ this.cacheManager.testIterationStart(null);
+ assertNull("Should not find entry",getThreadCacheEntry(LOCAL_HOST));
+ assertFalse("Should not find valid entry",this.cacheManager.inCache(url));
+ ((HttpMethodStub)httpMethod).expires=makeDate(new Date(System.currentTimeMillis()));
+ ((HttpMethodStub)httpMethod).cacheControl="public, max-age=5";
+ this.vary = "Something";
+ this.cacheManager.saveDetails(httpMethod, sampleResultOK);
+ assertNull("Should not find entry",getThreadCacheEntry(LOCAL_HOST));
+ assertFalse("Should not find valid entry",this.cacheManager.inCache(url));
+ this.vary = null;
+ }
+
public void testCacheHttpClientHEAD() throws Exception{
this.cacheManager.setUseExpires(true);
this.cacheManager.testIterationStart(null);
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1690478&r1=1690477&r2=1690478&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sun Jul 12 16:25:08 2015
@@ -158,6 +158,7 @@ Summary
<h3>Timers, Assertions, Config, Pre- & Post-Processors</h3>
<ul>
+<li><bug>58079</bug>Do not cache HTTP samples that have a Vary header when using a HTTP CacheManager.</li>
</ul>
<h3>Functions</h3>
Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1690478&r1=1690477&r2=1690478&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sun Jul 12 16:25:08 2015
@@ -3894,7 +3894,7 @@ If the requested document has not change
Likewise if the Expires date is in the future.
This may cause problems for Assertions.
</p>
-
+<note>Responses with a Vary header will not be cached.</note>
</description>
<properties>
<property name="Name" required="No">Descriptive name for this element that is shown in the tree. </property>