From fbcc36752362886ca620f4be28102b4e16cb90b7 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Wed, 15 Mar 2023 17:17:37 +0100 Subject: [PATCH] [BUGFIX] Only set Content-Type charset for text/html or JSON When using TYPO3 as a response for multipart result or application/binary responses, TSFE should not append "charset=utf-8" to the Content-Type HTTP response header. Resolves: #100189 Related: #99373 Related: #97550 Releases: main, 11.5 Change-Id: I645bb6941bb4bd01cb508a873e1add074c39ca57 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78132 Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Helmut Hummel <typo3@helhum.io> Reviewed-by: Markus Klein <markus.klein@typo3.org> Tested-by: Helmut Hummel <typo3@helhum.io> --- typo3/sysext/extbase/Classes/Core/Bootstrap.php | 3 +-- .../Classes/Controller/TypoScriptFrontendController.php | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/typo3/sysext/extbase/Classes/Core/Bootstrap.php b/typo3/sysext/extbase/Classes/Core/Bootstrap.php index b3c1385ca09f..af16aadb8ef6 100644 --- a/typo3/sysext/extbase/Classes/Core/Bootstrap.php +++ b/typo3/sysext/extbase/Classes/Core/Bootstrap.php @@ -164,10 +164,9 @@ class Bootstrap if (($typoScriptFrontendController = ($GLOBALS['TSFE'] ?? null)) instanceof TypoScriptFrontendController && $response->hasHeader('Content-Type') ) { - [$contentType] = explode(';', $response->getHeaderLine('Content-Type')); + $typoScriptFrontendController->setContentType($response->getHeaderLine('Content-Type')); // Do not send the header directly (see below) $response = $response->withoutHeader('Content-Type'); - $typoScriptFrontendController->setContentType($contentType); } if (headers_sent() === false) { diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php index 6cd1e8708c4d..b6ae6c8dcdf1 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -469,7 +469,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface * @todo Ticket: #63642 Should be refactored to a request/response model later * @internal Should only be used by TYPO3 core for now */ - protected string $contentType = 'text/html'; + protected string $contentType = 'text/html; charset=utf-8'; /** * Doctype to use @@ -2327,8 +2327,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface */ public function applyHttpHeadersToResponse(ResponseInterface $response): ResponseInterface { - // Set header for content-type + charset-encoding - $response = $response->withHeader('Content-Type', $this->contentType . '; charset=utf-8'); + $response = $response->withHeader('Content-Type', $this->contentType); // Set header for content language unless disabled $contentLanguage = (string)$this->language->getLocale(); if (empty($this->config['config']['disableLanguageHeader'])) { -- GitLab