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 2019/07/28 09:14:45 UTC

[jmeter] branch master updated: Bug 63574 - HTTP Cache Manager does not cache resource if Cache-Control header is missing

This is an automated email from the ASF dual-hosted git repository.

pmouawad pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new 5883d81  Bug 63574 - HTTP Cache Manager does not cache resource if Cache-Control header is missing
5883d81 is described below

commit 5883d81abf5f0b4e7f4134aa6560ba21a62f5c43
Author: pmouawad <p....@ubik-ingenierie.com>
AuthorDate: Sun Jul 28 11:14:31 2019 +0200

    Bug 63574 - HTTP Cache Manager does not cache resource if Cache-Control
    header is missing
    
    This resolves Bug 63574
---
 .../jmeter/protocol/http/control/CacheManager.java |  4 ++--
 .../http/control/TestCacheManagerBase.java         | 22 ++++++++++++++++++++++
 xdocs/changes.xml                                  |  3 ++-
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java b/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
index e1a599a..496d3b8 100644
--- a/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
@@ -254,7 +254,7 @@ public class CacheManager extends ConfigTestElement implements TestStateListener
                 expiresDate = extractExpiresDateFromExpires(expires);
             }
             // if no-cache is present, ensure that expiresDate remains null, which forces revalidation
-            if(cacheControl != null && !cacheControl.contains("no-cache")) {
+            if(cacheControl == null || !cacheControl.contains("no-cache")) {
                 expiresDate = extractExpiresDateFromCacheControl(lastModified,
                         cacheControl, expires, etag, url, date, maxAge, expiresDate);
                 // else expiresDate computed in (expires!=null) condition is used
@@ -298,7 +298,7 @@ public class CacheManager extends ConfigTestElement implements TestStateListener
             String cacheControl, String expires, String etag, String url,
             String date, final String maxAge, Date defaultExpiresDate) {
         // the max-age directive overrides the Expires header,
-        if (cacheControl.contains(maxAge)) {
+        if (cacheControl != null && cacheControl.contains(maxAge)) {
             long maxAgeInSecs = Long.parseLong(cacheControl
                     .substring(cacheControl.indexOf(maxAge) + maxAge.length())
                     .split("[, ]")[0] // Bug 51932 - allow for optional trailing
diff --git a/test/src/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java b/test/src/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java
index 4ea9e18..86ad065 100644
--- a/test/src/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java
+++ b/test/src/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java
@@ -264,6 +264,28 @@ public abstract class TestCacheManagerBase extends JMeterTestCase {
         assertNotNull("Should find entry", getThreadCacheEntry(LOCAL_HOST));
         assertFalse("Should not find valid entry", this.cacheManager.inCache(url));
     }
+    
+    @Test
+    public void testNoCacheControlNoMaxAgeNoExpireNoCacheControl() 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));
+        // No Cache-Control
+        // Expires is not set, however RFC recommends to use
+        // response_is_fresh = (freshness_lifetime > current_age)
+        // We set "currentAge == X seconds", thus response will considered to
+        // be fresh for the next 10% of X seconds == 0.1*X seconds
+        long start = System.currentTimeMillis();
+        long age = 30 * 1000; // 30 seconds
+        setLastModified(makeDate(new Date(start - age)));
+        cacheResult(sampleResultOK);
+        assertNotNull("Should find entry", getThreadCacheEntry(LOCAL_HOST));
+        assertTrue("Should find valid entry", this.cacheManager.inCache(url));
+        sleepTill(start + age / 10 + 10);
+        assertNotNull("Should find entry", getThreadCacheEntry(LOCAL_HOST));
+        assertFalse("Should not find valid entry", this.cacheManager.inCache(url));
+    }
 
     @Test
     public void testPrivateCacheNoMaxAgeNoExpire() throws Exception {
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 600e2b5..c7998cc 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -149,13 +149,14 @@ to view the last release notes of version 5.1.1.
     <li><bug>63364</bug>When setting <code>subresults.disable_renaming=true</code>, sub results are still renamed using their parent SampleLabel while they shouldn't. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
     <li><bug>63129</bug>JMeter can not identify encoding during first time page submission. Based partly on analysis and PR made by Naveen Nandwani (naveen.nandwani at india.nec.com)</li>
     <li><bug>62672</bug>HTTP Request sends double requests when using proxy with authentication. Based on patch by Artem Fedorov (artem.fedorov at blazemeter.com) and contributed by BlazeMeter.</li>
-    <li><bug>63469</bug>JMSPublisher: Race condition in jms.client.ClientPool#clearClient</li>
+    <li><bug>63574</bug>HTTP Cache Manager does not cache resource if <code>Cache-Control</code> header is missing.</li>
 </ul>
 
 <h3>Other Samplers</h3>
 <ul>
     <li><bug>63442</bug>Reduce scanning for <code>LogParser</code> implementations in AccessLogSamplerBeanInfo.</li>
     <li><bug>63563</bug>LdapExtSampler: When sampler fails with exception differing from NamingException, no SampleResult is generated</li>
+    <li><bug>63469</bug>JMSPublisher: Race condition in jms.client.ClientPool#clearClient</li>
 </ul>
 
 <h3>Controllers</h3>