* http headers
This commit is contained in:
parent
39b46f4626
commit
badc4de958
4 changed files with 43 additions and 22 deletions
|
@ -88,7 +88,7 @@ EOD;
|
||||||
public function rendering(Page $p)
|
public function rendering(Page $p)
|
||||||
{
|
{
|
||||||
foreach ($p->httpHeaders as $header) {
|
foreach ($p->httpHeaders as $header) {
|
||||||
\header($header);
|
\header($header[0], $header[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $p->nameTpl) {
|
if (null === $p->nameTpl) {
|
||||||
|
|
|
@ -202,6 +202,30 @@ abstract class Page extends Model
|
||||||
return $this;
|
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 заголовки страницы
|
* Возвращает HTTP заголовки страницы
|
||||||
* $this->httpHeaders
|
* $this->httpHeaders
|
||||||
|
@ -210,18 +234,22 @@ abstract class Page extends Model
|
||||||
*/
|
*/
|
||||||
protected function gethttpHeaders()
|
protected function gethttpHeaders()
|
||||||
{
|
{
|
||||||
$headers = $this->a['httpHeaders'];
|
$now = gmdate('D, d M Y H:i:s') . ' GMT';
|
||||||
if (! empty($status = $this->httpStatus())) {
|
|
||||||
$headers[] = $status;
|
$this->httpStatus()
|
||||||
}
|
->header('Cache-Control', 'no-cache, no-store, must-revalidate')
|
||||||
# $headers[] = 'X-Frame-Options: DENY';
|
->header('Content-type', 'text/html; charset=utf-8')
|
||||||
return $headers;
|
->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()
|
protected function httpStatus()
|
||||||
{
|
{
|
||||||
|
@ -234,16 +262,9 @@ abstract class Page extends Model
|
||||||
];
|
];
|
||||||
|
|
||||||
if (isset($list[$this->httpStatus])) {
|
if (isset($list[$this->httpStatus])) {
|
||||||
$status = 'HTTP/1.0 ';
|
$this->header('HTTP/1.0', $list[$this->httpStatus]);
|
||||||
|
|
||||||
if (isset($_SERVER['SERVER_PROTOCOL'])
|
|
||||||
&& \preg_match('%^HTTP/([12]\.[01])%', $_SERVER['SERVER_PROTOCOL'], $match)
|
|
||||||
) {
|
|
||||||
$status = 'HTTP/' . $match[1] . ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status . $list[$this->httpStatus];
|
|
||||||
}
|
}
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Maintenance extends Page
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Конструктор
|
* Конструктор
|
||||||
*
|
*
|
||||||
* @param Container $container
|
* @param Container $container
|
||||||
*/
|
*/
|
||||||
public function __construct(Container $container)
|
public function __construct(Container $container)
|
||||||
|
@ -25,6 +25,8 @@ class Maintenance extends Page
|
||||||
$this->titles = \ForkBB\__('Maintenance');
|
$this->titles = \ForkBB\__('Maintenance');
|
||||||
# $this->fNavigation = null; //????
|
# $this->fNavigation = null; //????
|
||||||
$this->maintenanceMessage = $this->c->config->o_maintenance_message;
|
$this->maintenanceMessage = $this->c->config->o_maintenance_message;
|
||||||
|
|
||||||
|
$this->header('Retry-After', '3600');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,9 +75,7 @@ class Redirect extends Page
|
||||||
protected function getHttpHeaders()
|
protected function getHttpHeaders()
|
||||||
{
|
{
|
||||||
if (null === $this->nameTpl) {
|
if (null === $this->nameTpl) {
|
||||||
$this->httpHeaders = [
|
$this->header('Location', $this->link);
|
||||||
'Location: ' . $this->link, //????
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
return parent::getHttpHeaders();
|
return parent::getHttpHeaders();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue