diff options
author | Andrew Dolgov <[email protected]> | 2022-11-24 23:31:33 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2022-11-24 23:31:33 +0300 |
commit | a30b9bb649d6e10a5d7c2feb73376669cf23ef68 (patch) | |
tree | 33716caf2286a0c544a2f053ea07c677aebd5fd4 /classes/diskcache.php | |
parent | be6bc72a742c5fb7f87a4495009ed71ff0fbb8d8 (diff) |
rework favicon storage to use DiskCache
Diffstat (limited to 'classes/diskcache.php')
-rw-r--r-- | classes/diskcache.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/classes/diskcache.php b/classes/diskcache.php index 70c3b7e2c..a00003516 100644 --- a/classes/diskcache.php +++ b/classes/diskcache.php @@ -210,6 +210,10 @@ class DiskCache implements Cache_Adapter { $this->adapter->set_dir($dir); } + public function remove(string $filename): bool { + return $this->adapter->remove($filename); + } + public function set_dir(string $dir) : void { $this->adapter->set_dir($dir); } @@ -290,6 +294,20 @@ class DiskCache implements Cache_Adapter { } public function send(string $filename) { + + if (!$this->exists($filename)) { + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); + echo "File not found."; + return false; + } + + $gmt_modified = gmdate("D, d M Y H:i:s", (int)$this->get_mtime($filename)) . " GMT"; + + if (($_SERVER['HTTP_IF_MODIFIED_SINCE'] ?? '') == $gmt_modified) { + header('HTTP/1.1 304 Not Modified'); + return false; + } + $mimetype = $this->adapter->get_mime_type($filename); if ($mimetype == "application/octet-stream") @@ -315,6 +333,15 @@ class DiskCache implements Cache_Adapter { header("Content-Disposition: inline; filename=\"{$filename}{$fake_extension}\""); header("Content-type: $mimetype"); + $stamp_expires = gmdate("D, d M Y H:i:s", + (int)$this->get_mtime($filename) + 86400 * Config::get(Config::CACHE_MAX_DAYS)) . " GMT"; + + header("Expires: $stamp_expires", true); + header("Last-Modified: $gmt_modified", true); + header("Cache-Control: public"); + + header_remove("Pragma"); + return $this->adapter->send($filename); } |