ModuleController: Rename ETag to etag and change Response headers (imageAction)

This commit is contained in:
Jennifer Mourek 2017-10-25 14:36:41 +02:00
parent 48742e1333
commit 12a694787b

View File

@ -148,14 +148,14 @@ class ModuleController extends DocController
$imageInfo = new SplFileInfo($imagePath); $imageInfo = new SplFileInfo($imagePath);
$ETag = md5($imageInfo->getMTime() . $imagePath); $etag = md5($imageInfo->getMTime() . $imagePath);
$lastModified = gmdate('D, d M Y H:i:s T', $imageInfo->getMTime()); $lastModified = gmdate('D, d M Y H:i:s T', $imageInfo->getMTime());
$match = false; $match = false;
if (isset($_SERER['HTTP_IF_NONE_MATCH'])) { if (isset($_SERER['HTTP_IF_NONE_MATCH'])) {
$ifNoneMatch = explode(', ', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); $ifNoneMatch = explode(', ', stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
foreach ($ifNoneMatch as $tag) { foreach ($ifNoneMatch as $tag) {
if ($tag === $ETag) { if ($tag === $etag) {
$match = true; $match = true;
break; break;
} }
@ -167,20 +167,16 @@ class ModuleController extends DocController
} }
} }
$finfo = new finfo();
$this->getResponse() $this->getResponse()
->setHeader('ETag', $ETag) ->setHeader('ETag', $etag)
->setHeader('Cache-Control', 'no-transform,public,max-age=3600', true) ->setHeader('Cache-Control', 'no-transform,public,max-age=3600,must-revalidate', true);
->setHeader('Last-Modified', $lastModified, true)
// Set additional headers for compatibility reasons (Cache-Control should have precedence) in case
// session.cache_limiter is set to no cache
->setHeader('Pragma', 'cache', true)
->setHeader('Expires', gmdate('D, d M Y H:i:s T', time() + 3600), true)
->setHeader('Content-Type', $finfo->file($imagePath, FILEINFO_MIME_TYPE));
if ($match) { if ($match) {
$this->getResponse()->setHttpResponseCode(304); $this->getResponse()->setHttpResponseCode(304);
} else { } else {
$finfo = new finfo();
$this->getResponse()
->setHeader('Content-Type', $finfo->file($imagePath, FILEINFO_MIME_TYPE));
readfile($imagePath); readfile($imagePath);
} }
} }