Optimized clean response handling

This commit is contained in:
Bernd Bestel 2021-07-12 17:08:59 +02:00
parent 2cc4f4d382
commit f1da3ef5e8
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 2 additions and 3 deletions

View File

@ -101,4 +101,6 @@ $errorMiddleware->setDefaultErrorHandler(
);
$app->add(new CorsMiddleware($app->getResponseFactory()));
ob_clean(); // No response output before here
$app->run();

View File

@ -49,7 +49,6 @@ class CalendarApiController extends BaseApiController
$vCalendar->addEvent($vEvent);
}
ob_clean(); // Make sure to ONLY return the file
$response->write((new CalendarFactory())->createCalendar($vCalendar));
$response = $response->withHeader('Content-Type', 'text/calendar; charset=utf-8');
return $response->withHeader('Content-Disposition', 'attachment; filename="grocy.ics"');

View File

@ -49,7 +49,6 @@ class FilesApiController extends BaseApiController
if (file_exists($filePath))
{
ob_clean(); // Make sure to ONLY return the file
$response->write(file_get_contents($filePath));
$response = $response->withHeader('Cache-Control', 'max-age=2592000');
$response = $response->withHeader('Content-Type', mime_content_type($filePath));
@ -81,7 +80,6 @@ class FilesApiController extends BaseApiController
if (file_exists($filePath))
{
ob_clean(); // Make sure to ONLY return the file
$response->write(file_get_contents($filePath));
$response = $response->withHeader('Cache-Control', 'max-age=2592000');
$response = $response->withHeader('Content-Type', mime_content_type($filePath));