summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/df.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/df.php b/app/df.php
index 80aec5a..348daa2 100644
--- a/app/df.php
+++ b/app/df.php
@@ -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 . "\"");