Merge pull request #3034 from Icinga/bugfix/doc-module-sends-wrong-content-type-for-images-2918

ModulesController: use setter for headers and response code
This commit is contained in:
lippserd 2017-11-07 09:05:11 +01:00 committed by GitHub
commit 37275ee799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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,19 +167,16 @@ class ModuleController extends DocController
} }
} }
header('ETag: "' . $ETag . '"'); $this->getResponse()
header('Cache-Control: no-transform,public,max-age=3600'); ->setHeader('ETag', $etag)
header('Last-Modified: ' . $lastModified); ->setHeader('Cache-Control', 'no-transform,public,max-age=3600,must-revalidate', true);
// Set additional headers for compatibility reasons (Cache-Control should have precedence) in case
// session.cache_limiter is set to no cache
header('Pragma: cache');
header('Expires: ' . gmdate('D, d M Y H:i:s T', time() + 3600));
if ($match) { if ($match) {
header('HTTP/1.1 304 Not Modified'); $this->getResponse()->setHttpResponseCode(304);
} else { } else {
$finfo = new finfo(); $finfo = new finfo();
header('Content-Type: ' . $finfo->file($imagePath, FILEINFO_MIME_TYPE)); $this->getResponse()
->setHeader('Content-Type', $finfo->file($imagePath, FILEINFO_MIME_TYPE));
readfile($imagePath); readfile($imagePath);
} }
} }