diff --git a/src/Controllers/PostContentController.php b/src/Controllers/PostContentController.php index a5dbe523..64bd38c4 100644 --- a/src/Controllers/PostContentController.php +++ b/src/Controllers/PostContentController.php @@ -40,13 +40,12 @@ final class PostContentController extends AbstractController { $post = $this->postService->getByName($postName); - $options = new \StdClass; - $options->customFileName = sprintf('%s_%s.%s', + $customFileName = sprintf('%s_%s.%s', $this->config->basic->serviceName, $post->getName(), strtolower(MimeHelper::getExtension($post->getContentMimeType()))); - $this->networkingService->serveFile($this->fileDao->getFullPath($post->getContentPath()), $options); + $this->networkingService->serveFile($this->fileDao->getFullPath($post->getContentPath()), $customFileName); } public function getPostThumbnail($postName, $size) diff --git a/src/Services/NetworkingService.php b/src/Services/NetworkingService.php index 1731e63b..1a60c0a6 100644 --- a/src/Services/NetworkingService.php +++ b/src/Services/NetworkingService.php @@ -1,5 +1,6 @@ httpHelper = $httpHelper; } - public function serveFile($fullPath, $options = []) + public function serveFile($fullPath, $customFileName = null) { - $daysToLive = isset($options->daysToLive) - ? $options->daysToLive - : 7; - + $daysToLive = 7; $secondsToLive = $daysToLive * 24 * 60 * 60; $lastModified = filemtime($fullPath); $eTag = md5($fullPath . $lastModified); @@ -34,15 +32,10 @@ class NetworkingService $this->httpHelper->setHeader('Pragma', 'public'); $this->httpHelper->setHeader('Cache-Control', 'public, max-age=' . $secondsToLive); $this->httpHelper->setHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $secondsToLive)); + $this->httpHelper->setHeader( 'Content-Type', MimeHelper::getMimeTypeFromFile($fullPath)); - if (isset($options->customFileName)) - $this->httpHelper->setHeader('Content-Disposition', 'inline; filename="' . $options->customFileName . '"'); - - $this->httpHelper->setHeader( - 'Content-Type', - isset($options->mimeType) - ? $options->mimeType - : mime_content_type($fullPath)); + if ($customFileName) + $this->httpHelper->setHeader('Content-Disposition', 'inline; filename="' . $customFileName . '"'); if (strtotime($ifModifiedSince) === $lastModified or $eTagHeader === $eTag) {