StyleSheet/JavaScript: Also include Cache-Control when answering with a 304

Without Cache-Control, the browser may invalidate its cached file and we're
serving the file again on the next request.

refs #2917
This commit is contained in:
Johannes Meyer 2017-08-22 09:33:28 +02:00
parent 6702ccb2a7
commit beb3326631
2 changed files with 3 additions and 4 deletions

View File

@ -98,13 +98,13 @@ class JavaScript
$request = Icinga::app()->getRequest();
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
header('Cache-Control: public');
if (! $noCache && FileCache::etagMatchesFiles($files)) {
header("HTTP/1.1 304 Not Modified");
return;
} else {
$etag = FileCache::etagForFiles($files);
}
header('Cache-Control: public');
header('ETag: "' . $etag . '"');
header('Content-Type: application/javascript');

View File

@ -182,6 +182,7 @@ class StyleSheet
$request = $styleSheet->app->getRequest();
$response = $styleSheet->app->getResponse();
$response->setHeader('Cache-Control', 'public', true);
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
@ -194,9 +195,7 @@ class StyleSheet
$etag = FileCache::etagForFiles($styleSheet->lessCompiler->getLessFiles());
$response
->setHeader('Cache-Control', 'public', true)
->setHeader('ETag', $etag, true)
$response->setHeader('ETag', $etag, true)
->setHeader('Content-Type', 'text/css', true);
$cacheFile = 'icinga-' . $etag . ($minified ? '.min' : '') . '.css';