public function viewFileAction(ParamFetcher $paramFetcher)
{
$path = $paramFetcher->get('path');
if (is_numeric($path)) {
$path = $this->webFilesystem->getPath($path);
}
$this->checkAccess($path, ACL::MODE_VIEW);
$file = $this->webFilesystem->getFile($path);
if ($file->isDir()) {
return;
}
$ifModifiedSince = $this->pageStack->getRequest()->headers->get('If-Modified-Since');
if (isset($ifModifiedSince) && strtotime($ifModifiedSince) == $file->getModifiedTime()) {
// Client's cache IS current, so we just respond '304 Not Modified'.
$response = new Response();
$response->setStatusCode(304);
$response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $file->getModifiedTime()) . ' GMT');
return $response;
}
$content = $this->webFilesystem->read($path);
$mime = $file->getMimeType();
$expires = 3600;
//1 h
$response = new Response();
$response->headers->set('Content-Type', $mime);
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'max-age=' . $expires);
$response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $file->getModifiedTime()) . ' GMT');
$response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
$response->setContent($content);
return $response;
}