From 2c2c4d268de03fce1349cf027ac0d95ecb61a5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCder?= Date: Sat, 24 Oct 2026 01:05:40 +0200 Subject: [PATCH 1/2] Added FILE_OCTET_STREAM as Content-Type --- Classes/Definition/ContentTypeDefinition.php | 2 ++ Classes/Middleware/MiddlewareApiAbstract.php | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Classes/Definition/ContentTypeDefinition.php b/Classes/Definition/ContentTypeDefinition.php index 1d2bdc7..bbe0394 100644 --- a/Classes/Definition/ContentTypeDefinition.php +++ b/Classes/Definition/ContentTypeDefinition.php @@ -8,6 +8,8 @@ enum ContentTypeDefinition { case DEFAULT; + case FILE_OCTET_STREAM; + case FILE_PLAIN; case IMAGE_JPEG; diff --git a/Classes/Middleware/MiddlewareApiAbstract.php b/Classes/Middleware/MiddlewareApiAbstract.php index 766067f..05ada1b 100644 --- a/Classes/Middleware/MiddlewareApiAbstract.php +++ b/Classes/Middleware/MiddlewareApiAbstract.php @@ -181,10 +181,27 @@ public function createResponse(string $string, ContentTypeDefinition $contentTyp break; + case ContentTypeDefinition::FILE_OCTET_STREAM: + $response = $response + ->withHeader('Content-Type', 'application/octet-stream') + ->withHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"') + ->withHeader('Content-Transfer-Encoding', 'binary') + ->withHeader('Expires', '0') + ->withHeader('Cache-Control', 'must-revalidate') + ->withHeader('Pragma', 'public') + ->withHeader('Content-Length', (string) strlen($string)) + ; + + break; + case ContentTypeDefinition::FILE_PLAIN: $response = $response ->withHeader('Content-Type', 'text/plain; charset=utf-8') - ->withAddedHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"') + ->withHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"') + ->withHeader('Expires', '0') + ->withHeader('Cache-Control', 'must-revalidate') + ->withHeader('Pragma', 'public') + ->withHeader('Content-Length', (string) strlen($string)) ; break; From 65abf7a7d3da618af42c1348a51655bd28ce8381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCder?= Date: Sat, 24 Oct 2026 01:06:33 +0200 Subject: [PATCH 2/2] Added withHeaders parameter to createResponse --- Classes/Middleware/MiddlewareApiAbstract.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Classes/Middleware/MiddlewareApiAbstract.php b/Classes/Middleware/MiddlewareApiAbstract.php index 05ada1b..b520459 100644 --- a/Classes/Middleware/MiddlewareApiAbstract.php +++ b/Classes/Middleware/MiddlewareApiAbstract.php @@ -170,8 +170,9 @@ public function buildUri(int $pageId, array $additionalGetParams = [], ?string $ /** * @param ContentTypeDefinition $contentType defaults to JSON content type if omitted + * @param array $withHeaders */ - public function createResponse(string $string, ContentTypeDefinition $contentType = ContentTypeDefinition::DEFAULT, string $fileName = ''): void { + public function createResponse(string $string, ContentTypeDefinition $contentType = ContentTypeDefinition::DEFAULT, string $fileName = '', array $withHeaders = []): void { $response = $this->responseFactory->createResponse(); switch ($contentType) { @@ -220,6 +221,10 @@ public function createResponse(string $string, ContentTypeDefinition $contentTyp break; } + foreach ($withHeaders as $name => $value) { + $response = $response->withHeader($name, $value); + } + $response->getBody()->write($string); $this->response = $response;