From 1edabe3b00c6f2a73f287a678b0ea9cda62eaa13 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 16 Jun 2015 10:25:27 -0600 Subject: [PATCH] added page level overrides of `etag` and `last_modified` header flags --- system/src/Grav/Common/Grav.php | 4 +-- system/src/Grav/Common/Page/Page.php | 42 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 0c8b5348e..806cbaa62 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -312,13 +312,13 @@ class Grav extends Container } // Set the last modified time - if ($this['config']->get('system.pages.last_modified')) { + if ($page->lastModified()) { $last_modified_date = gmdate('D, d M Y H:i:s', $page->modified()) . ' GMT'; header('Last-Modified: ' . $last_modified_date); } // Calculate a Hash based on the raw file - if ($this['config']->get('system.pages.etag')) { + if ($page->eTag()) { header('ETag: ' . md5($page->raw() . $page->modified())); } diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 7037dfe40..c1dbd8e59 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -78,6 +78,8 @@ class Page protected $process; protected $summary_size; protected $markdown_extra; + protected $etag; + protected $last_modified; /** * @var Page Unmodified (original) version of the page. Used for copying and moving the page. @@ -277,6 +279,12 @@ class Page if (isset($this->header->expires)) { $this->expires = intval($this->header->expires); } + if (isset($this->header->etag)) { + $this->etag = (bool)$this->header->etag; + } + if (isset($this->header->last_modified)) { + $this->last_modified = (bool)$this->header->last_modified; + } } @@ -1142,6 +1150,40 @@ class Page return $this->modified; } + /** + * Gets and sets the option to show the etag header for the page. + * + * @param boolean $var show etag header + * @return boolean show etag header + */ + public function eTag($var = null) + { + if ($var !== null) { + $this->etag = $var; + } + if (!isset($this->etag)) { + $this->etag = (bool) self::getGrav()['config']->get('system.pages.etag'); + } + return $this->etag; + } + + /** + * Gets and sets the option to show the last_modified header for the page. + * + * @param boolean $var show last_modified header + * @return boolean show last_modified header + */ + public function lastModified($var = null) + { + if ($var !== null) { + $this->last_modified = $var; + } + if (!isset($this->last_modified)) { + $this->last_modified = (bool) self::getGrav()['config']->get('system.pages.last_modified'); + } + return $this->last_modified; + } + /** * Gets and sets the path to the .md file for this Page object. *