added page level overrides of etag and last_modified header flags

This commit is contained in:
Andy Miller
2015-06-16 10:25:27 -06:00
parent 019fdd65e9
commit 1edabe3b00
2 changed files with 44 additions and 2 deletions

View File

@@ -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()));
}

View File

@@ -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.
*