use etag preferably for caching

This commit is contained in:
Evan Prodromou 2010-08-31 00:54:33 -04:00
parent c8a69f433c
commit 388495f6b1
1 changed files with 24 additions and 16 deletions

View File

@ -982,32 +982,40 @@ class Action extends HTMLOutputter // lawsuit
function handle($argarray=null) function handle($argarray=null)
{ {
header('Vary: Accept-Encoding,Cookie'); header('Vary: Accept-Encoding,Cookie');
$lm = $this->lastModified(); $lm = $this->lastModified();
$etag = $this->etag(); $etag = $this->etag();
if ($etag) { if ($etag) {
header('ETag: ' . $etag); header('ETag: ' . $etag);
} }
if ($lm) { if ($lm) {
header('Last-Modified: ' . date(DATE_RFC1123, $lm)); header('Last-Modified: ' . date(DATE_RFC1123, $lm));
if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) { if ($this->isCacheable()) {
$if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE']; header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
$ims = strtotime($if_modified_since); header( "Cache-Control: private, must-revalidate, max-age=0" );
if ($lm <= $ims) { header( "Pragma: underwear-catapult");
}
}
if ($etag) {
$if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ? $if_none_match = (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) ?
$_SERVER['HTTP_IF_NONE_MATCH'] : null; $_SERVER['HTTP_IF_NONE_MATCH'] : null;
if (!$if_none_match || if ($if_none_match && $this->_hasEtag($etag, $if_none_match)) {
!$etag ||
$this->_hasEtag($etag, $if_none_match)) {
header('HTTP/1.1 304 Not Modified'); header('HTTP/1.1 304 Not Modified');
// Better way to do this? // Better way to do this?
exit(0); exit(0);
} }
} }
}
if ($this->isCacheable()) { if ($lm && array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
header( "Cache-Control: private, must-revalidate, max-age=0" ); $ims = strtotime($if_modified_since);
if ($lm <= $ims) {
header('HTTP/1.1 304 Not Modified');
// Better way to do this?
exit(0);
} }
} }
} }