add ETag handling

darcs-hash:20081202044211-5ed1f-d8779be7681fc21eebff3c0c56fdde892c2fa3da.gz
This commit is contained in:
Evan Prodromou 2008-12-01 23:42:11 -05:00
parent cad6f78fe6
commit be33850c5f

View File

@ -40,6 +40,10 @@ class Action { // lawsuit
return NULL; return NULL;
} }
function etag() {
return NULL;
}
function is_readonly() { function is_readonly() {
return false; return false;
} }
@ -62,6 +66,11 @@ class Action { // lawsuit
function handle($argarray=NULL) { function handle($argarray=NULL) {
$lm = $this->last_modified(); $lm = $this->last_modified();
$etag = $this->etag();
if ($etag) {
header('ETag: ' . $etag);
}
if ($lm) { if ($lm) {
header('Last-Modified: ' . date(DATE_RFC822, $lm)); header('Last-Modified: ' . date(DATE_RFC822, $lm));
@ -69,6 +78,7 @@ class Action { // lawsuit
if ($if_modified_since) { if ($if_modified_since) {
$ims = strtotime($if_modified_since); $ims = strtotime($if_modified_since);
if ($lm <= $ims) { if ($lm <= $ims) {
if (!$etag || $this->_has_etag($etag, $_SERVER['HTTP_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);
@ -76,6 +86,11 @@ class Action { // lawsuit
} }
} }
} }
}
function _has_etag($etag, $if_none_match) {
return ($if_none_match) && in_array($etag, explode(',', $if_none_match));
}
function boolean($key, $def=false) { function boolean($key, $def=false) {
$arg = strtolower($this->trimmed($key)); $arg = strtolower($this->trimmed($key));