Improve the eTag handling of file downloads
authorAlexander Ebert <ebert@woltlab.com>
Sat, 25 May 2024 13:16:56 +0000 (15:16 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 8 Jun 2024 10:19:40 +0000 (12:19 +0200)
wcfsetup/install/files/lib/action/FileDownloadAction.class.php
wcfsetup/install/files/lib/system/file/processor/AttachmentFileProcessor.class.php

index 90be9214e94c380dadbad34fe71e723abaf84fa0..224697e674e4788b06f03afe906cb27d344cb87a 100644 (file)
@@ -97,26 +97,21 @@ final class FileDownloadAction implements RequestHandlerInterface
         }
 
         $eTag = \sprintf(
-            '"W/%d-%s"',
-            $file->fileID,
-            \substr($file->fileHash, 0, 8),
-        );
-        $nonWeakETag =  \sprintf(
             '"%d-%s"',
             $file->fileID,
             \substr($file->fileHash, 0, 8),
         );
 
         $httpIfNoneMatch = \array_map(
-            static fn ($tag) => \preg_replace('~^"W/~', '"', $tag),
+            static fn ($tag) => \preg_replace('~^W/~', '', $tag),
             Header::splitList($request->getHeaderLine('if-none-match'))
         );
-        if (\in_array($nonWeakETag, $httpIfNoneMatch, true)) {
+        if (\in_array($eTag, $httpIfNoneMatch, true)) {
             $emptyResponse = new EmptyResponse(304);
-            if ($response->getHeader('expires')) {
+            if ($response->hasHeader('expires')) {
                 $emptyResponse = $emptyResponse->withHeader('expires', $response->getHeader('expires'));
             }
-            if ($response->getHeader('cache-control')) {
+            if ($response->hasHeader('cache-control')) {
                 $emptyResponse = $emptyResponse->withHeader('cache-control', $response->getHeader('cache-control'));
             }
 
index cc6b7211315c905919a211134f4aec325c63535e..998a8daedd0a376695b8aec0a9ede8f92ee5fecd 100644 (file)
@@ -44,7 +44,7 @@ final class AttachmentFileProcessor extends AbstractFileProcessor
     {
         $attachmentHandler = $this->getAttachmentHandlerFromContext($context);
         if ($attachmentHandler === null) {
-            // This can only happen whenhe associated object has vanished
+            // This can only happen when the associated object has vanished
             // while the file was being processed. There is nothing we can
             // meaningfully do here.
             return;