From 65e771eb8fb1f2fe03fb29a4c53ba7b9a6b66891 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Sun, 19 Mar 2023 22:27:27 +0100 Subject: [PATCH] [BUGFIX] Only set Content-Type charset if no charset is given 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/+/78171 Tested-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Achim Fritz <af@achimfritz.de> Reviewed-by: Achim Fritz <af@achimfritz.de> --- typo3/sysext/extbase/Classes/Core/Bootstrap.php | 3 +-- .../Classes/Controller/TypoScriptFrontendController.php | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/typo3/sysext/extbase/Classes/Core/Bootstrap.php b/typo3/sysext/extbase/Classes/Core/Bootstrap.php index 2b9b79b8bcbe..3ebf72177ead 100644 --- a/typo3/sysext/extbase/Classes/Core/Bootstrap.php +++ b/typo3/sysext/extbase/Classes/Core/Bootstrap.php @@ -180,10 +180,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 04a94d4e3ca6..7b7d450441a8 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -2913,8 +2913,11 @@ class TypoScriptFrontendController implements LoggerAwareInterface public function applyHttpHeadersToResponse(ResponseInterface $response): ResponseInterface { // Set header for charset-encoding unless disabled - if (empty($this->config['config']['disableCharsetHeader'])) { + if (empty($this->config['config']['disableCharsetHeader']) && !str_contains($this->contentType, 'charset=')) { $response = $response->withHeader('Content-Type', $this->contentType . '; charset=' . trim($this->metaCharset)); + } elseif ($this->contentType && $this->contentType !== 'text/html') { + // send the contentType, if defined differently than text/html + $response = $response->withHeader('Content-Type', $this->contentType); } // Set header for content language unless disabled $contentLanguage = $this->language->getTwoLetterIsoCode(); -- GitLab