Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for the previous commit

  • Loading branch information...
commit 2d738d962133fa52c903a1155d67de1d46acd539 1 parent bc5fa2c
@DaSourcerer authored
Showing with 35 additions and 19 deletions.
  1. +35 −19 framework/web/filters/CHttpCacheFilter.php
View
54 framework/web/filters/CHttpCacheFilter.php
@@ -25,7 +25,6 @@ class CHttpCacheFilter extends CFilter
* @var string|integer
*/
public $lastModified;
-
/**
* Expression for the last modification date. If set, this takes precedence over {@link lastModified}.
* @var string|callback
@@ -36,39 +35,44 @@ class CHttpCacheFilter extends CFilter
* @var mixed
*/
public $etagSeed;
-
/**
* Expression for the ETag seed. If set, this takes precedence over {@link etag}.
* @var string|callback
*/
public $etagSeedExpression;
-
/**
- * Http cache control headers
+ * Http cache control headers. Set this to an empty string in order to keep this
+ * header from being sent entirely.
* @var string
*/
public $cacheControl = 'max-age=3600, public';
-
+
+ /**
+ * Performs the pre-action filtering.
+ * @param CFilterChain $filterChain the filter chain that the filter is on.
+ * @return boolean whether the filtering process should continue and the action should be executed.
+ */
public function preFilter($filterChain)
{
// Only cache GET and HEAD requests
if(!in_array(Yii::app()->getRequest()->getRequestType(), array('GET', 'HEAD')))
return true;
-
+
$lastModified=$this->getLastModifiedValue();
$etag=$this->getEtagValue();
-
+
if($etag===false&&$lastModified===false)
return true;
-
+
if($etag)
header('ETag: '.$etag);
-
+
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])&&isset($_SERVER['HTTP_IF_NONE_MATCH']))
{
if($this->checkLastModified($lastModified)&&$this->checkEtag($etag))
{
$this->send304Header();
+ $this->sendCacheControlHeader();
return false;
}
}
@@ -77,6 +81,7 @@ public function preFilter($filterChain)
if($this->checkLastModified($lastModified))
{
$this->send304Header();
+ $this->sendCacheControlHeader();
return false;
}
}
@@ -85,6 +90,7 @@ public function preFilter($filterChain)
if($this->checkEtag($etag))
{
$this->send304Header();
+ $this->sendCacheControlHeader();
return false;
}
@@ -92,13 +98,13 @@ public function preFilter($filterChain)
if($lastModified)
header('Last-Modified: '.date('r', $lastModified));
-
- header('Cache-Control: ' . $this->cacheControl);
+
+ $this->sendCacheControlHeader();
return true;
}
-
+
/**
- * Gets the last modified value from either {@link lastModifiedExpression} or {@lastModified}
+ * Gets the last modified value from either {@link lastModifiedExpression} or {@link lastModified}
* and converts it into a unix timestamp if necessary
* @throws CException
* @return integer|boolean A unix timestamp or false if neither lastModified nor
@@ -116,7 +122,7 @@ protected function getLastModifiedValue()
array('{value}'=>$value)));
return $lastModified;
}
-
+
if($this->lastModified)
{
if(is_numeric($this->lastModified)&&$this->lastModified==(int)$this->lastModified)
@@ -127,7 +133,7 @@ protected function getLastModifiedValue()
}
return false;
}
-
+
/**
* Gets the ETag out of either {@link etagSeedExpression} or {@link etagSeed}
* @return string|boolean Either a quoted string serving as ETag or false if neither etagSeed nor etagSeedExpression have been set
@@ -140,20 +146,20 @@ protected function getEtagValue()
return $this->generateEtag($this->etagSeed);
return false;
}
-
+
/**
* Check if the etag supplied by the client matches our generated one
- * @param string $etag
+ * @param string $etag the supplied etag
* @return boolean true if the supplied etag matches $etag
*/
protected function checkEtag($etag)
{
return isset($_SERVER['HTTP_IF_NONE_MATCH'])&&$_SERVER['HTTP_IF_NONE_MATCH']==$etag;
}
-
+
/**
* Checks if the last modified date supplied by the client is still up to date
- * @param integer $lastModified
+ * @param integer $lastModified the last modified date
* @return boolean true if the last modified date sent by the client is newer or equal to $lastModified
*/
protected function checkLastModified($lastModified)
@@ -170,6 +176,16 @@ protected function send304Header()
}
/**
+ * Sends the cache control header to the client
+ * @see cacheControl
+ * @since 1.1.12
+ */
+ protected function sendCacheControlHeader()
+ {
+ header('Cache-Control: '.$this->cacheControl, true);
+ }
+
+ /**
* Generates a quoted string out of the seed
* @param mixed $seed Seed for the ETag
*/

0 comments on commit 2d738d9

Please sign in to comment.
Something went wrong with that request. Please try again.