diff options
Diffstat (limited to 'app/df.php')
-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 . "\""); |