diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 683f17dab..85631966a 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -270,6 +270,25 @@ abstract class Utils } else { $new_length = $size; header("Content-Length: " . $size); + + if (Grav::instance()['config']->get('system.cache.enabled')) { + $expires = Grav::instance()['config']->get('system.pages.expires'); + if ($expires > 0) { + $expires_date = gmdate('D, d M Y H:i:s T', time() + $expires); + header('Cache-Control: max-age=' . $expires); + header('Expires: ' . $expires_date); + header('Pragma: cache'); + } + header('Last-Modified: ' . gmdate("D, d M Y H:i:s T", filemtime($file))); + + // Return 304 Not Modified if the file is already cached in the browser + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && + strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= filemtime($file)) + { + header('HTTP/1.1 304 Not Modified'); + exit(); + } + } } /* output the file itself */