diff --git a/app/Core/View.php b/app/Core/View.php index bec3b590..cc26f308 100644 --- a/app/Core/View.php +++ b/app/Core/View.php @@ -88,7 +88,7 @@ EOD; public function rendering(Page $p) { foreach ($p->httpHeaders as $header) { - \header($header); + \header($header[0], $header[1]); } if (null === $p->nameTpl) { diff --git a/app/Models/Page.php b/app/Models/Page.php index fbaf337c..b453cb35 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -202,6 +202,30 @@ abstract class Page extends Model return $this; } + /** + * Добавляет HTTP заголовок + * + * @param string $key + * @param string $value + * @param bool $replace + * + * @return Page + */ + public function header($key, $value, $replace = true) + { + if ('HTTP/' === \substr($key, 0, 5)) { + if (\preg_match('%^HTTP/\d\.\d%', $_SERVER['SERVER_PROTOCOL'], $match)) { + $key = $match[0]; + } else { + $key = 'HTTP/1.1'; + } + } else { + $key .= ':'; + } + $this->a['httpHeaders'][] = ["{$key} {$value}", $replace]; + return $this; + } + /** * Возвращает HTTP заголовки страницы * $this->httpHeaders @@ -210,18 +234,22 @@ abstract class Page extends Model */ protected function gethttpHeaders() { - $headers = $this->a['httpHeaders']; - if (! empty($status = $this->httpStatus())) { - $headers[] = $status; - } -# $headers[] = 'X-Frame-Options: DENY'; - return $headers; + $now = gmdate('D, d M Y H:i:s') . ' GMT'; + + $this->httpStatus() + ->header('Cache-Control', 'no-cache, no-store, must-revalidate') + ->header('Content-type', 'text/html; charset=utf-8') + ->header('Date', $now) + ->header('Last-Modified', $now) + ->header('Expires', $now); + + return $this->a['httpHeaders']; } /** - * Возвращает HTTP статус страницы или null + * Устанавливает HTTP статус страницы * - * @return null|string + * @return Page */ protected function httpStatus() { @@ -234,16 +262,9 @@ abstract class Page extends Model ]; if (isset($list[$this->httpStatus])) { - $status = 'HTTP/1.0 '; - - if (isset($_SERVER['SERVER_PROTOCOL']) - && \preg_match('%^HTTP/([12]\.[01])%', $_SERVER['SERVER_PROTOCOL'], $match) - ) { - $status = 'HTTP/' . $match[1] . ' '; - } - - return $status . $list[$this->httpStatus]; + $this->header('HTTP/1.0', $list[$this->httpStatus]); } + return $this; } /** diff --git a/app/Models/Pages/Maintenance.php b/app/Models/Pages/Maintenance.php index 7cd2633c..76f387b4 100644 --- a/app/Models/Pages/Maintenance.php +++ b/app/Models/Pages/Maintenance.php @@ -9,7 +9,7 @@ class Maintenance extends Page { /** * Конструктор - * + * * @param Container $container */ public function __construct(Container $container) @@ -25,6 +25,8 @@ class Maintenance extends Page $this->titles = \ForkBB\__('Maintenance'); # $this->fNavigation = null; //???? $this->maintenanceMessage = $this->c->config->o_maintenance_message; + + $this->header('Retry-After', '3600'); } /** diff --git a/app/Models/Pages/Redirect.php b/app/Models/Pages/Redirect.php index 0eab7ecb..52d194dc 100644 --- a/app/Models/Pages/Redirect.php +++ b/app/Models/Pages/Redirect.php @@ -75,9 +75,7 @@ class Redirect extends Page protected function getHttpHeaders() { if (null === $this->nameTpl) { - $this->httpHeaders = [ - 'Location: ' . $this->link, //???? - ]; + $this->header('Location', $this->link); } return parent::getHttpHeaders(); }