Merge pull request #86 from lbryio/header_fix

always send headers, tweak header functions
This commit is contained in:
Alex Grin 2016-11-28 13:03:03 -05:00 committed by GitHub
commit ab09ad4cc8
2 changed files with 25 additions and 19 deletions

View file

@ -21,16 +21,15 @@ class Controller
throw new Exception('use response::setheader instead of returning headers');
}
if ($viewTemplate === null)
{
return;
}
if (!$viewTemplate)
{
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']);
@ -40,6 +39,8 @@ class Controller
$content = View::render($viewTemplate, $viewParameters + ['fullPage' => true]);
Response::setContent($layout ? View::render('layout/basic', ['content' => $content] + $layoutParams) : $content);
}
Response::setDefaultSecurityHeaders();
if (Request::isGzipAccepted())
{

View file

@ -168,13 +168,18 @@ class Response
}
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::setHeaders(array_filter([
'Content-Disposition' => 'attachment;filename=' . $name,
'Content-Type' => $type ? 'application/zip' : null,
'Content-Length' => $size ?: null,
'X-Content-Type-Options' => $noSniff ? 'nosniff' : null,
static::HEADER_CONTENT_TYPE => $type,
static::HEADER_CONTENT_LENGTH => $size ?: null,
static::HEADER_CONTENT_TYPE_OPTIONS => $noSniff ? 'nosniff' : null,
]));
}