Skip to content

Commit

Permalink
Debugger optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Oct 17, 2018
1 parent 27aa5e8 commit 3742be1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# v1.6.0-beta.4
## mm/dd/2018

1. [](#new)
* Added `Page::httpResponseCode()` and `Page::httpHeaders()` methods
1. [](#improved)
* Added apcu autoloader optimization

Expand Down
53 changes: 53 additions & 0 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,59 @@ public function modifyHeader($key, $value)
$this->header->{$key} = $value;
}

/**
* @return int
*/
public function httpResponseCode()
{
return (int)($this->header()->http_response_code ?? 200);
}

public function httpHeaders()
{
$headers = [];

$grav = Grav::instance();
$format = $this->templateFormat();
$cache_control = $this->cacheControl();
$expires = $this->expires();

// Set Content-Type header
$headers['Content-Type'] = Utils::getMimeByExtension($format, 'text/html');

// Calculate Expires Headers if set to > 0
if ($expires > 0) {
$expires_date = gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT';
if (!$cache_control) {
$headers['Cache-Control'] = 'max-age=' . $expires;
}
$headers['Expires'] = $expires_date;
}

// Set Cache-Control header
if ($cache_control) {
$headers['Cache-Control'] = strtolower($cache_control);
}

// Set Last-Modified header
if ($this->lastModified()) {
$last_modified_date = gmdate('D, d M Y H:i:s', $this->modified()) . ' GMT';
$headers['Last-Modified'] = $last_modified_date;
}

// Calculate ETag based on the raw file
if ($this->eTag()) {
$headers['ETag'] = '"' . md5($this->raw() . $this->modified()).'"';
}

// Set Vary: Accept-Encoding header
if ($grav['config']->get('system.pages.vary_accept_encoding', false)) {
$headers['Vary'] = 'Accept-Encoding';
}

return $headers;
}

/**
* Get the summary.
*
Expand Down

0 comments on commit 3742be1

Please sign in to comment.