summaryrefslogtreecommitdiff
path: root/system/helpers/expires.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-01-07 10:41:19 -0800
committerBharat Mediratta <bharat@menalto.com>2010-01-07 10:41:19 -0800
commitc711bf1b1fcf7840467a7a044b1f511e7b69c139 (patch)
treeee84a16b5ce4448fd41ba7ffa2cb2381b225e206 /system/helpers/expires.php
parent31454d37b3ea02104925f1976609576c5f09c0c6 (diff)
parent10c05c855a1634a60048a52e8d90bc51f187ede7 (diff)
Merge branch 'master' of git@github.com:gallery/gallery3 into bharat_dev
Diffstat (limited to 'system/helpers/expires.php')
-rw-r--r--system/helpers/expires.php30
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 = "";'));