1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-11 00:24:11 +02:00

Added 'maxAge' option (removed 'setExpires') and changed behavior so that conditional GET is still implemented when max-age/Expires is sent.

This commit is contained in:
Steve Clay
2008-07-22 20:43:27 +00:00
parent 6cdfb77083
commit 3f5c9f4de0

View File

@@ -85,10 +85,10 @@ class HTTP_ConditionalGet {
* without testing. Effectively this disables conditional GET. * without testing. Effectively this disables conditional GET.
* (default false) * (default false)
* *
* 'setExpires': (mixed) set this to a timestamp or GMT date to send an * 'maxAge': (int) if given, this will set the Cache-Control max-age in
* Expires header with the content instead of ETag/Last-Modified. If given, * seconds, and also set the Expires header to the equivalent GMT date.
* Conditional GETs will not be performed, but the public/private * After the max-age period has passed, the browser will again send a
* Cache-Control header will still be sent. (default null) * conditional GET to revalidate its cache.
* *
* @return null * @return null
*/ */
@@ -96,17 +96,18 @@ class HTTP_ConditionalGet {
$scope = (isset($spec['isPublic']) && $spec['isPublic']) $scope = (isset($spec['isPublic']) && $spec['isPublic'])
? 'public' ? 'public'
: 'private'; : 'private';
// allow far-expires header $maxAge = 0;
if (isset($spec['setExpires'])) { // backwards compatibility (can be removed later)
if (is_numeric($spec['setExpires'])) { if (isset($spec['setExpires'])
$spec['setExpires'] = self::gmtDate($spec['setExpires']); && is_numeric($spec['setExpires'])
} && ! isset($spec['maxAge'])) {
$this->_headers = array( $spec['maxAge'] = $spec['setExpires'] - $_SERVER['REQUEST_TIME'];
'Cache-Control' => $scope }
,'Expires' => $spec['setExpires'] if (isset($spec['maxAge'])) {
$maxAge = $spec['maxAge'];
$this->_headers['Expires'] = self::gmtDate(
$_SERVER['REQUEST_TIME'] + $spec['maxAge']
); );
$this->cacheIsValid = false;
return;
} }
if (isset($spec['lastModifiedTime'])) { if (isset($spec['lastModifiedTime'])) {
// base both headers on time // base both headers on time
@@ -118,7 +119,7 @@ class HTTP_ConditionalGet {
$this->_setEtag($spec['contentHash'], $scope); $this->_setEtag($spec['contentHash'], $scope);
} }
} }
$this->_headers['Cache-Control'] = "max-age=0, {$scope}, must-revalidate"; $this->_headers['Cache-Control'] = "max-age={$maxAge}, {$scope}, must-revalidate";
// invalidate cache if disabled, otherwise check // invalidate cache if disabled, otherwise check
$this->cacheIsValid = (isset($spec['invalidate']) && $spec['invalidate']) $this->cacheIsValid = (isset($spec['invalidate']) && $spec['invalidate'])
? false ? false