]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
add ETag handling
authorEvan Prodromou <evan@controlyourself.ca>
Tue, 2 Dec 2008 04:42:11 +0000 (23:42 -0500)
committerEvan Prodromou <evan@controlyourself.ca>
Tue, 2 Dec 2008 04:42:11 +0000 (23:42 -0500)
darcs-hash:20081202044211-5ed1f-d8779be7681fc21eebff3c0c56fdde892c2fa3da.gz

lib/action.php

index 754bbdbae8982d5d9ded155b78dc848f1964013c..fc69efcce3d1733041cabf3325f24f49f582b7f2 100644 (file)
@@ -40,6 +40,10 @@ class Action { // lawsuit
                return NULL;
        }
 
+       function etag() {
+               return NULL;
+       }
+
        function is_readonly() {
                return false;
        }
@@ -62,6 +66,11 @@ class Action { // lawsuit
        function handle($argarray=NULL) {
 
                $lm = $this->last_modified();
+               $etag = $this->etag();
+
+               if ($etag) {
+                       header('ETag: ' . $etag);
+               }
 
                if ($lm) {
                        header('Last-Modified: ' . date(DATE_RFC822, $lm));
@@ -69,14 +78,20 @@ class Action { // lawsuit
                        if ($if_modified_since) {
                                $ims = strtotime($if_modified_since);
                                if ($lm <= $ims) {
-                                       header('HTTP/1.1 304 Not Modified');
-                                       # Better way to do this?
-                                       exit(0);
+                                       if (!$etag || $this->_has_etag($etag, $_SERVER['HTTP_IF_NONE_MATCH'])) {
+                                               header('HTTP/1.1 304 Not Modified');
+                                               # Better way to do this?
+                                               exit(0);
+                                       }
                                }
                        }
                }
        }
 
+       function _has_etag($etag, $if_none_match) {
+               return ($if_none_match) && in_array($etag, explode(',', $if_none_match));
+       }
+
        function boolean($key, $def=false) {
                $arg = strtolower($this->trimmed($key));