mirror of
https://github.com/mrclay/minify.git
synced 2025-08-18 20:01:21 +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:
@@ -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;
|
||||
}
|
||||
|
@@ -42,4 +42,3 @@ $cg->setContentLength(strlen($content));
|
||||
$cg->sendHeaders();
|
||||
send_slowly($content);
|
||||
|
||||
?>
|
@@ -38,4 +38,3 @@ $cg->sendHeaders();
|
||||
|
||||
send_slowly($content);
|
||||
|
||||
?>
|
@@ -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());
|
||||
|
||||
?>
|
@@ -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
|
||||
));
|
||||
|
||||
?>
|
@@ -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;
|
||||
}
|
||||
|
||||
?>
|
@@ -34,4 +34,3 @@ echo send_slowly(get_content(array(
|
||||
,'explain' => $explain
|
||||
)));
|
||||
|
||||
?>
|
@@ -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
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user