diff options
Diffstat (limited to 'src/application')
| -rw-r--r-- | src/application/actions/ctheme/get.php | 24 | 
1 files 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; |