diff options
Diffstat (limited to 'core/modules/file/src')
-rw-r--r-- | core/modules/file/src/Entity/File.php | 11 | ||||
-rw-r--r-- | core/modules/file/src/FileInterface.php | 9 | ||||
-rw-r--r-- | core/modules/file/src/Hook/FileDownloadHook.php | 2 |
3 files changed, 21 insertions, 1 deletions
diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php index 0022fec6add1..bc310eeb7f22 100644 --- a/core/modules/file/src/Entity/File.php +++ b/core/modules/file/src/Entity/File.php @@ -300,4 +300,15 @@ class File extends ContentEntityBase implements FileInterface { Cache::invalidateTags($tags); } + /** + * {@inheritdoc} + */ + public function getDownloadHeaders(): array { + return [ + 'Content-Type' => $this->getMimeType(), + 'Content-Length' => $this->getSize(), + 'Cache-Control' => 'private', + ]; + } + } diff --git a/core/modules/file/src/FileInterface.php b/core/modules/file/src/FileInterface.php index 588009cb475b..efa6627790fe 100644 --- a/core/modules/file/src/FileInterface.php +++ b/core/modules/file/src/FileInterface.php @@ -142,4 +142,13 @@ interface FileInterface extends ContentEntityInterface, EntityChangedInterface, */ public function getCreatedTime(); + /** + * Examines a file entity and returns content headers for download. + * + * @return array + * An associative array of headers, as expected by + * \Symfony\Component\HttpFoundation\StreamedResponse. + */ + public function getDownloadHeaders(): array; + } diff --git a/core/modules/file/src/Hook/FileDownloadHook.php b/core/modules/file/src/Hook/FileDownloadHook.php index 21086c5eb114..1dee2310d57f 100644 --- a/core/modules/file/src/Hook/FileDownloadHook.php +++ b/core/modules/file/src/Hook/FileDownloadHook.php @@ -58,7 +58,7 @@ class FileDownloadHook { return -1; } // Access is granted. - return file_get_content_headers($file); + return $file->getDownloadHeaders(); } } |