mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-31 09:21:26 +00:00
Merge pull request #86 from lbryio/header_fix
always send headers, tweak header functions
This commit is contained in:
commit
ab09ad4cc8
2 changed files with 25 additions and 19 deletions
|
@ -21,25 +21,26 @@ class Controller
|
||||||
throw new Exception('use response::setheader instead of returning headers');
|
throw new Exception('use response::setheader instead of returning headers');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($viewTemplate === null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$viewTemplate)
|
if (!$viewTemplate)
|
||||||
{
|
{
|
||||||
throw new LogicException('All execute methods must return a template or NULL.');
|
if ($viewTemplate !== null)
|
||||||
|
{
|
||||||
|
throw new LogicException('All execute methods must return a template or NULL.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$layout = !(isset($viewParameters['_no_layout']) && $viewParameters['_no_layout']);
|
||||||
|
unset($viewParameters['_no_layout']);
|
||||||
|
|
||||||
|
$layoutParams = $viewParameters[View::LAYOUT_PARAMS] ?? [];
|
||||||
|
unset($viewParameters[View::LAYOUT_PARAMS]);
|
||||||
|
|
||||||
|
$content = View::render($viewTemplate, $viewParameters + ['fullPage' => true]);
|
||||||
|
|
||||||
|
Response::setContent($layout ? View::render('layout/basic', ['content' => $content] + $layoutParams) : $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
$layout = !(isset($viewParameters['_no_layout']) && $viewParameters['_no_layout']);
|
|
||||||
unset($viewParameters['_no_layout']);
|
|
||||||
|
|
||||||
$layoutParams = $viewParameters[View::LAYOUT_PARAMS] ?? [];
|
|
||||||
unset($viewParameters[View::LAYOUT_PARAMS]);
|
|
||||||
|
|
||||||
$content = View::render($viewTemplate, $viewParameters + ['fullPage' => true]);
|
|
||||||
|
|
||||||
Response::setContent($layout ? View::render('layout/basic', ['content' => $content] + $layoutParams) : $content);
|
|
||||||
Response::setDefaultSecurityHeaders();
|
Response::setDefaultSecurityHeaders();
|
||||||
if (Request::isGzipAccepted())
|
if (Request::isGzipAccepted())
|
||||||
{
|
{
|
||||||
|
|
|
@ -168,13 +168,18 @@ class Response
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setDownloadHttpHeaders($name, $type = null, $size = null, $noSniff = true)
|
public static function setDownloadHttpHeaders($name, $type = null, $size = null, $noSniff = true)
|
||||||
|
{
|
||||||
|
static::setBinaryHttpHeaders($type, $size, $noSniff);
|
||||||
|
static::setHeader('Content-Disposition', 'attachment;filename=' . $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setBinaryHttpHeaders($type, $size = null, $noSniff = true)
|
||||||
{
|
{
|
||||||
static::setGzipResponseContent(false); // in case its already compressed
|
static::setGzipResponseContent(false); // in case its already compressed
|
||||||
static::setHeaders(array_filter([
|
static::setHeaders(array_filter([
|
||||||
'Content-Disposition' => 'attachment;filename=' . $name,
|
static::HEADER_CONTENT_TYPE => $type,
|
||||||
'Content-Type' => $type ? 'application/zip' : null,
|
static::HEADER_CONTENT_LENGTH => $size ?: null,
|
||||||
'Content-Length' => $size ?: null,
|
static::HEADER_CONTENT_TYPE_OPTIONS => $noSniff ? 'nosniff' : null,
|
||||||
'X-Content-Type-Options' => $noSniff ? 'nosniff' : null,
|
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue