1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-19 12:21:20 +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()); $isValid = ($this->resourceMatchedEtag() || $this->resourceNotModified());
if ($isValid) { if ($isValid) {
// overwrite headers, only need 304 $this->_headers['_responseCode'] = 'HTTP/1.0 304 Not Modified';
$this->_headers = array(
'_responseCode' => 'HTTP/1.0 304 Not Modified'
);
} }
return $isValid; return $isValid;
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,7 +7,7 @@ function send_slowly($content)
while ($chunk = array_shift($content)) { while ($chunk = array_shift($content)) {
sleep(1); sleep(1);
echo $chunk; echo $chunk;
ob_flush(); ob_get_level() && ob_flush();
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="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="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="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> </ul>
<h2>Notes</h2> <h2>Notes</h2>
<h3>How to distinguish 200 and 304 responses</h3> <h3>How to distinguish 200 and 304 responses</h3>
@@ -62,4 +62,3 @@ to verify headers and content being sent.</p>
return $content; return $content;
} }
?>

View File

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

View File

@@ -16,7 +16,10 @@ function test_HTTP_ConditionalGet()
,'inm' => null ,'inm' => null
,'ims' => $gmtTime ,'ims' => $gmtTime
,'exp' => array( ,'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 ,'isValid' => true
) )
) )
@@ -25,7 +28,10 @@ function test_HTTP_ConditionalGet()
,'inm' => null ,'inm' => null
,'ims' => $gmtTime . ';' ,'ims' => $gmtTime . ';'
,'exp' => array( ,'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 ,'isValid' => true
) )
) )
@@ -34,7 +40,10 @@ function test_HTTP_ConditionalGet()
,'inm' => "\"badEtagFoo\", \"{$lmTime}pri\"" ,'inm' => "\"badEtagFoo\", \"{$lmTime}pri\""
,'ims' => null ,'ims' => null
,'exp' => array( ,'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 ,'isValid' => true
) )
) )