diff options
Diffstat (limited to 'system/helpers/expires.php')
| -rw-r--r-- | system/helpers/expires.php | 30 | 
1 files changed, 20 insertions, 10 deletions
| diff --git a/system/helpers/expires.php b/system/helpers/expires.php index ce0482c8..81468ce3 100644 --- a/system/helpers/expires.php +++ b/system/helpers/expires.php @@ -2,9 +2,7 @@  /**   * Controls headers that effect client caching of pages   * - * $Id: expires.php 4679 2009-11-10 01:45:52Z isaiah $ - * - * @package    Core + * @package    Kohana   * @author     Kohana Team   * @copyright  (c) 2007-2009 Kohana Team   * @license    http://kohanaphp.com/license @@ -15,14 +13,19 @@ class expires_Core {  	 * Sets the amount of time before content expires  	 *  	 * @param   integer Seconds before the content expires -	 * @return  integer Timestamp when the content expires +	 * @param   integer Last modified timestamp in seconds(optional) + 	 * @return  integer Timestamp when the content expires  	 */ -	public static function set($seconds = 60) +	public static function set($seconds = 60, $last_modified=null)  	{  		$now = time();  		$expires = $now + $seconds; + 		if (empty($last_modified)) + 		{ + 			$last_modified = $now; + 		} -		header('Last-Modified: '.gmdate('D, d M Y H:i:s T', $now)); + 		 header('Last-Modified: '.gmdate('D, d M Y H:i:s T', $last_modified));  		// HTTP 1.0  		header('Expires: '.gmdate('D, d M Y H:i:s T', $expires)); @@ -66,26 +69,33 @@ class expires_Core {  	 * @uses    expires::get()  	 *  	 * @param   integer         Maximum age of the content in seconds +	 * @param   integer Last modified timestamp in seconds(optional)  	 * @return  integer|boolean Timestamp of the If-Modified-Since header or FALSE when header is lacking or malformed  	 */ -	public static function check($seconds = 60) +	public static function check($seconds = 60, $modified=null)  	{  		if ($last_modified = expires::get())  		{ -			$expires = $last_modified + $seconds; +			$now = time(); + + 			if (empty($last_modified)) + 			{ + 				$last_modified = $now; + 			}  			$max_age = $expires - time(); -			if ($max_age > 0) +			if ($modified <= $last_modified)  			{  				// Content has not expired  				header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');  				header('Last-Modified: '.gmdate('D, d M Y H:i:s T', $last_modified)); +				$expires = $now + $seconds;  				// HTTP 1.0  				header('Expires: '.gmdate('D, d M Y H:i:s T', $expires));  				// HTTP 1.1 -				header('Cache-Control: max-age='.$max_age); +				header('Cache-Control: max-age='.$seconds);  				// Clear any output  				Event::add('system.display', create_function('', 'Kohana::$output = "";')); | 
