From 2cc4f4d3821b8a65a4e11a370cb137d05a01ec43 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 12 Jul 2021 15:34:26 +0200 Subject: [PATCH] Make sure to clean the response before returning files Was a problemw when returning images and there were leading empty lines in config.php which seem to get added to the response always... --- controllers/CalendarApiController.php | 1 + controllers/FilesApiController.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/controllers/CalendarApiController.php b/controllers/CalendarApiController.php index 8d3db47e..7cf3d7e2 100644 --- a/controllers/CalendarApiController.php +++ b/controllers/CalendarApiController.php @@ -49,6 +49,7 @@ 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"'); diff --git a/controllers/FilesApiController.php b/controllers/FilesApiController.php index 5dbca1ec..4ff4980c 100644 --- a/controllers/FilesApiController.php +++ b/controllers/FilesApiController.php @@ -49,6 +49,7 @@ 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)); @@ -80,6 +81,7 @@ 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));