Skip to content

Commit

Permalink
[!!!][TASK] Remove typoscript option config.disableCharsetHeader
Browse files Browse the repository at this point in the history
This option is obsolete nowadays, as PSR-7 is setting
the headers at the end of the script / when emitting
a Response, this way the header can be modified at any time.

Resolves: #97550
Releases: main
Change-Id: I0602e4fd0a20461d49a554f66f36442894e96fd4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74518
Tested-by: core-ci <typo3@b13.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Josef Glatz <josefglatz@gmail.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
bmack committed May 5, 2022
1 parent ae00ad4 commit 3a7c8b1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 24 deletions.
@@ -0,0 +1,45 @@
.. include:: /Includes.rst.txt

.. _breaking-97550-1651697278
========================================================================
Breaking: #97550 - TypoScript option config.disableCharsetHeader removed
========================================================================

See :issue:`97550`

Description
===========

The TypoScript flag :ts:`config.disableCharsetHeader` has been completely removed
from TYPO3 Core.

This option was used to avoid sending HTTP headers of type "Content-Type" to
the client. This flag was mainly used to overcome a technical limitation to
override the Content-Type information back in TYPO3 v4.x.


Impact
======

TYPO3 now always sends the `Content-Type` header to the client in the TYPO3
Frontend.


Affected installations
======================

TYPO3 installations having this option enabled via TypoScript.


Migration
=========

It is not needed to set this option. Even when Extbase plugins return JSON-based
Responses, the Content-Type header is already modified.

In special cases, when custom headers are required, it is possible to modify
the headers via a PHP-based PSR-15 middleware, or via TypoScript with
"config.additionalHeaders".

.. index:: TypoScript, NotScanned, ext:frontend
17 changes: 3 additions & 14 deletions typo3/sysext/extbase/Classes/Core/Bootstrap.php
Expand Up @@ -163,24 +163,13 @@ protected function handleFrontendRequest(ServerRequestInterface $request): strin
$this->clearCacheOnError();
}

// In case TSFE is available and this is a json response, we have
// to take the TypoScript settings regarding charset into account.
// @todo Since HTML5 only utf-8 is a valid charset, this settings should be deprecated
// In case TSFE is available and this is a json response, we have to let TSFE know we have a specific Content-Type
if (($typoScriptFrontendController = ($GLOBALS['TSFE'] ?? null)) instanceof TypoScriptFrontendController
&& str_starts_with($response->getHeaderLine('Content-Type'), 'application/json')
) {
// Unset the already defined Content-Type
// Do not send the header directly (see below)
$response = $response->withoutHeader('Content-Type');
if (empty($typoScriptFrontendController->config['config']['disableCharsetHeader'])) {
// If the charset header is *not* disabled in configuration,
// TypoScriptFrontendController will send the header later with the Content-Type which we set here.
$typoScriptFrontendController->setContentType('application/json');
} else {
// Although the charset header is disabled in configuration, we *must* send a Content-Type header here.
// Content-Type headers optionally carry charset information at the same time.
// Since we have the information about the charset, there is no reason to not include the charset information although disabled in TypoScript.
$response = $response->withHeader('Content-Type', 'application/json; charset=utf-8');
}
$typoScriptFrontendController->setContentType('application/json');
}

if (headers_sent() === false) {
Expand Down
Expand Up @@ -2165,10 +2165,8 @@ public function isINTincScript()
*/
public function applyHttpHeadersToResponse(ResponseInterface $response): ResponseInterface
{
// Set header for charset-encoding unless disabled
if (empty($this->config['config']['disableCharsetHeader'])) {
$response = $response->withHeader('Content-Type', $this->contentType . '; charset=utf-8');
}
// Set header for content-type + charset-encoding
$response = $response->withHeader('Content-Type', $this->contentType . '; charset=utf-8');
// Set header for content language unless disabled
$contentLanguage = $this->language->getTwoLetterIsoCode();
if (empty($this->config['config']['disableLanguageHeader']) && !empty($contentLanguage)) {
Expand Down
5 changes: 0 additions & 5 deletions typo3/sysext/t3editor/Resources/Private/tsref.xml
Expand Up @@ -315,11 +315,6 @@ This value is overridden by the value set in the page-record (field="cache_timeo
Use this feature in templates supplying other content-types than HTML. That could be an image or a WAP-page!]]></description>
<default><![CDATA[false]]></default>
</property>
<property name="disableCharsetHeader" type="boolean">
<description><![CDATA[By default a HTTP header "Content-Type: text/html; charset..." is sent. This option will disable that.]]></description>
<default><![CDATA[
]]></default>
</property>
<property name="disablePrefixComment" type="boolean">
<description><![CDATA[If set, the stdWrap property "prefixComment" will be disabled, thus preventing any revealing and spaceconsuming comments in the HTML source code.]]></description>
<default><![CDATA[
Expand Down
Expand Up @@ -255,7 +255,6 @@
'disableAllHeaderCode': kw('disableAllHeaderCode'),
'disableAltText': kw('disableAltText'),
'disableBodyTag': kw('disableBodyTag'),
'disableCharsetHeader': kw('disableCharsetHeader'),
'disabled': kw('disabled'),
'disableDelete': kw('disableDelete'),
'disableHideAtCopy': kw('disableHideAtCopy'),
Expand Down

0 comments on commit 3a7c8b1

Please sign in to comment.