Fix the ETag handling
authorAlexander Ebert <ebert@woltlab.com>
Sat, 18 May 2024 11:34:59 +0000 (13:34 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 8 Jun 2024 10:19:39 +0000 (12:19 +0200)
wcfsetup/install/files/lib/action/FileDownloadAction.class.php

index 506c05c6d1848dd1fa2aa8ee29509c7b7a8282ce..90be9214e94c380dadbad34fe71e723abaf84fa0 100644 (file)
@@ -108,11 +108,19 @@ final class FileDownloadAction implements RequestHandlerInterface
         );
 
         $httpIfNoneMatch = \array_map(
-            static fn ($tag) => \preg_replace('^"W/', '"', $tag),
-            Header::splitList($request->getHeaderLine('HTTP_IF_NONE_MATCH'))
+            static fn ($tag) => \preg_replace('~^"W/~', '"', $tag),
+            Header::splitList($request->getHeaderLine('if-none-match'))
         );
         if (\in_array($nonWeakETag, $httpIfNoneMatch, true)) {
-            return new EmptyResponse(304);
+            $emptyResponse = new EmptyResponse(304);
+            if ($response->getHeader('expires')) {
+                $emptyResponse = $emptyResponse->withHeader('expires', $response->getHeader('expires'));
+            }
+            if ($response->getHeader('cache-control')) {
+                $emptyResponse = $emptyResponse->withHeader('cache-control', $response->getHeader('cache-control'));
+            }
+
+            return $emptyResponse;
         }
 
         return $response