Use Header::make() for complicated headers

This commit is contained in:
Giuseppe Criscione 2021-07-20 16:25:39 +02:00
parent 0c91f35119
commit 72b43d084d
2 changed files with 4 additions and 2 deletions

View File

@ -3,6 +3,7 @@
namespace Formwork\Response;
use Formwork\Utils\FileSystem;
use Formwork\Utils\Header;
use Formwork\Utils\HTTPResponse;
class FileResponse extends Response
@ -14,7 +15,7 @@ class FileResponse extends Response
{
$headers += [
'Content-Type' => FileSystem::mimeType($path),
'Content-Disposition' => $download ? 'attachment; filename="' . basename($path) . '"' : 'inline',
'Content-Disposition' => !$download ? 'inline' : Header::make(['attachment', 'filename' => basename($path)]),
'Content-Length' => FileSystem::fileSize($path)
];
parent::__construct(FileSystem::read($path), $status, $headers);

View File

@ -3,6 +3,7 @@
namespace Formwork\Response;
use Formwork\Parsers\JSON;
use Formwork\Utils\Header;
class JSONResponse extends Response
{
@ -12,7 +13,7 @@ class JSONResponse extends Response
public function __construct(array $data, int $status = 200, array $headers = [])
{
$headers += [
'Content-Type' => 'application/json; charset=utf-8'
'Content-Type' => Header::make(['application/json', 'charset' => 'utf-8'])
];
parent::__construct(JSON::encode($data), $status, $headers);
}