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

Completed HTTP_ConditionalGet change to accept 'maxAge' not prevent conditional GETs. Also 304 responses now have the full Cache-Control/Last-Modified/ETag headers so max-age will be honored after each 304 response.

This commit is contained in:
Steve Clay
2008-07-22 23:05:06 +00:00
parent 3f5c9f4de0
commit 3ddc831f20
8 changed files with 26 additions and 27 deletions

View File

@@ -225,10 +225,7 @@ class HTTP_ConditionalGet {
}
$isValid = ($this->resourceMatchedEtag() || $this->resourceNotModified());
if ($isValid) {
// overwrite headers, only need 304
$this->_headers = array(
'_responseCode' => 'HTTP/1.0 304 Not Modified'
);
$this->_headers['_responseCode'] = 'HTTP/1.0 304 Not Modified';
}
return $isValid;
}

View File

@@ -42,4 +42,3 @@ $cg->setContentLength(strlen($content));
$cg->sendHeaders();
send_slowly($content);
?>

View File

@@ -38,4 +38,3 @@ $cg->sendHeaders();
send_slowly($content);
?>

View File

@@ -31,7 +31,7 @@ $content = get_content(array(
,'explain' => $explain
));
require '../../Encoder.php';
require 'HTTP/Encoder.php';
$he = new HTTP_Encoder(array(
'content' => get_content(array(
'title' => $title
@@ -44,5 +44,3 @@ $he->encode();
// connection
$he->sendHeaders();
send_slowly($he->getContent());
?>

View File

@@ -5,18 +5,18 @@ require 'HTTP/ConditionalGet.php';
// far expires
$cg = new HTTP_ConditionalGet(array(
'setExpires' => (time() + 86400 * 365) // 1 yr
'maxAge' => 20
,'lastModifiedTime' => filemtime(__FILE__)
));
$cg->sendHeaders();
// generate, send content
$title = 'Expires date is known';
$title = 'Last-Modified + Expires';
$explain = '
<p>Here we set "setExpires" to a timestamp or GMT date string. This results in
<code>$cacheIsValid</code> always being false, so content is always served, but
with an Expires header.
<p><strong>Note:</strong> This isn\'t a conditional GET, but is useful if you\'re
used to the HTTP_ConditionalGet workflow already.</p>
<p>Here we set a static "lastModifiedTime" and "maxAge" to 20. The browser
will consider this document fresh for 20 seconds, then revalidate its cache. After
the 304 response, the cache will be good for another 20 seconds. Unless you force
a reload, there will only be 304 responses for this page after the initial download.
';
require '_include.php';
@@ -25,4 +25,3 @@ echo get_content(array(
,'explain' => $explain
));
?>

View File

@@ -7,7 +7,7 @@ function send_slowly($content)
while ($chunk = array_shift($content)) {
sleep(1);
echo $chunk;
ob_flush();
ob_get_level() && ob_flush();
flush();
}
}
@@ -31,7 +31,7 @@ function get_content($data)
<li><a href="2.php">Last-Modified is known : add Content-Length</a></li>
<li><a href="3.php">Last-Modified is unknown : use hash of content for ETag</a></li>
<li><a href="4.php">ConditionalGet + Encoder</a></li>
<li><a href="5.php">Expires date is known</a></li>
<li><a href="5.php">Last-Modified + Expires</a></li>
</ul>
<h2>Notes</h2>
<h3>How to distinguish 200 and 304 responses</h3>
@@ -62,4 +62,3 @@ to verify headers and content being sent.</p>
return $content;
}
?>

View File

@@ -34,4 +34,3 @@ echo send_slowly(get_content(array(
,'explain' => $explain
)));
?>

View File

@@ -16,7 +16,10 @@ function test_HTTP_ConditionalGet()
,'inm' => null
,'ims' => $gmtTime
,'exp' => array(
'_responseCode' => 'HTTP/1.0 304 Not Modified'
'Last-Modified' => $gmtTime
,'ETag' => "\"{$lmTime}pri\""
,'Cache-Control' => 'max-age=0, private, must-revalidate'
,'_responseCode' => 'HTTP/1.0 304 Not Modified'
,'isValid' => true
)
)
@@ -25,7 +28,10 @@ function test_HTTP_ConditionalGet()
,'inm' => null
,'ims' => $gmtTime . ';'
,'exp' => array(
'_responseCode' => 'HTTP/1.0 304 Not Modified'
'Last-Modified' => $gmtTime
,'ETag' => "\"{$lmTime}pri\""
,'Cache-Control' => 'max-age=0, private, must-revalidate'
,'_responseCode' => 'HTTP/1.0 304 Not Modified'
,'isValid' => true
)
)
@@ -34,7 +40,10 @@ function test_HTTP_ConditionalGet()
,'inm' => "\"badEtagFoo\", \"{$lmTime}pri\""
,'ims' => null
,'exp' => array(
'_responseCode' => 'HTTP/1.0 304 Not Modified'
'Last-Modified' => $gmtTime
,'ETag' => "\"{$lmTime}pri\""
,'Cache-Control' => 'max-age=0, private, must-revalidate'
,'_responseCode' => 'HTTP/1.0 304 Not Modified'
,'isValid' => true
)
)