diff options
author | Malf Furious <m@lfurio.us> | 2019-03-24 01:41:06 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2019-03-24 01:41:06 -0400 |
commit | ff716dad07085e2734c6af65661dbc95269c404d (patch) | |
tree | fdff6bb5ebc92f1d3abb6f5672198cef1c253ea7 | |
parent | 6e11d642995e2b2644464ef0bb21528e5e0c2456 (diff) | |
parent | 4586d033f6cfdd9df6f1036ced25dd202b462aaa (diff) | |
download | scrott-ff716dad07085e2734c6af65661dbc95269c404d.tar.gz scrott-ff716dad07085e2734c6af65661dbc95269c404d.zip |
Merge branch 'feature/cache-df'
-rw-r--r-- | app/df.php | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -37,11 +37,28 @@ function serveResource(string $uri, ?string $filename = NULL) : void { $f = fopen($uri, "rb"); + /* no file */ if (!$f) exit; + /* enable client caching */ + header("Cache-Control: max-age=0"); + header("Pragma: cache"); + + $hash = hash_file("sha256", $uri); + + /* validate client cache */ + if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && + $_SERVER['HTTP_IF_NONE_MATCH'] == $hash) + { + header("HTTP/1.1 304 Not Modified"); + exit; + } + + /* resource metadata */ header("Content-Type: " . mime_content_type($uri)); header("Content-Length: " . filesize($uri)); + header("ETag: " . $hash); if ($filename) header("Content-Disposition: attachment; filename=\"" . $filename . "\""); |