Fix the `expires` header and force lowercased http headers
authorAlexander Ebert <ebert@woltlab.com>
Sat, 18 May 2024 11:08:19 +0000 (13:08 +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 38576edfe45d9b714214d0073b5b88ca00779e9d..506c05c6d1848dd1fa2aa8ee29509c7b7a8282ce 100644 (file)
@@ -83,18 +83,17 @@ final class FileDownloadAction implements RequestHandlerInterface
 
         $lifetimeInSeconds = $processor->getFileCacheDuration($file)->lifetimeInSeconds;
         if ($lifetimeInSeconds !== null) {
-            $expiresAt = \sprintf(
-                '%s GMT',
-                \gmdate('D, d M Y H:i:s', $lifetimeInSeconds)
-            );
+            $expiresAt = (new \DateTimeImmutable('@' . \TIME_NOW))
+                ->modify("+{$lifetimeInSeconds} seconds")
+                ->format(\DateTimeImmutable::RFC7231);
             $maxAge = \sprintf(
                 'max-age=%d, private',
                 $lifetimeInSeconds ?: 0,
             );
 
             $response = $response
-                ->withHeader('Expires', $expiresAt)
-                ->withHeader('Cache-control', $maxAge);
+                ->withHeader('expires', $expiresAt)
+                ->withHeader('cache-control', $maxAge);
         }
 
         $eTag = \sprintf(
@@ -122,6 +121,6 @@ final class FileDownloadAction implements RequestHandlerInterface
                 'content-disposition',
                 $contentDisposition->forFilename($file->filename),
             )
-            ->withHeader('ETag', $eTag);
+            ->withHeader('etag', $eTag);
     }
 }