From c81ecbf2192ffa5643b0e6d14c8e86610c3a1fb6 Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Tue, 10 Dec 2024 11:47:59 +0100 Subject: Small tweak --- src/application/actions/ctheme/get.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/application/actions/ctheme/get.php b/src/application/actions/ctheme/get.php index 79f6353..558f8d2 100644 --- a/src/application/actions/ctheme/get.php +++ b/src/application/actions/ctheme/get.php @@ -2,6 +2,7 @@ // options $enableLogging = true; +$useEtag = true; $etag_strip_gzip_suffix = true; $cssFatal = function(string $msg): never { @@ -25,7 +26,7 @@ header("Content-Type: text/css; charset=UTF-8"); header("Cache-Control: no-cache"); // Disable Apache's gzip filter, as it interferes with our ETag // (Apache adds '-gzip' as a ETag suffix) -if (!$etag_strip_gzip_suffix) +if ($useEtag && !$etag_strip_gzip_suffix) apache_setenv('no-gzip', '1'); $themeName = $_GET["theme"] ?? $_COOKIE["theme"] ?? env("MYSTIC_FORUM_THEME") ?? "default"; @@ -59,17 +60,22 @@ foreach ($theme->files as $file) { } else $cssError($buffer, "Could not include file $file"); } -$etag = md5($buffer); -$ifNoneMatch = $_SERVER["HTTP_IF_NONE_MATCH"] ?? null; -if ($ifNoneMatch !== null) { - $ifNoneMatch = trim($ifNoneMatch, '"'); - if ($etag_strip_gzip_suffix) - $ifNoneMatch = preg_replace('/-gzip$/', '', $ifNoneMatch); +$ifNoneMatch = null; +if ($useEtag) { + $etag = md5($buffer); + + $ifNoneMatch = $_SERVER["HTTP_IF_NONE_MATCH"] ?? null; + if ($ifNoneMatch !== null) { + $ifNoneMatch = trim($ifNoneMatch, '"'); + if ($etag_strip_gzip_suffix) + $ifNoneMatch = preg_replace('/-gzip$/', '', $ifNoneMatch); + } + + header("ETag: \"$etag\""); } -header("ETag: \"$etag\""); -if ($ifNoneMatch === $etag) +if ($useEtag && $ifNoneMatch === $etag) http_response_code(304); else echo $buffer; -- cgit v1.2.3