-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] FE: Move Content-Length header to middleware
Resolves: #83828 Releases: master Change-Id: Id5f85a5ae38260cc1a1bf730b365a9b1c425bc7e Reviewed-on: https://review.typo3.org/55627 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com> Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Benjamin Franzke <bfr@qbus.de> Tested-by: Benjamin Franzke <bfr@qbus.de> Reviewed-by: Susanne Moog <susanne.moog@typo3.org> Tested-by: Susanne Moog <susanne.moog@typo3.org>
- Loading branch information
1 parent
437015c
commit f6a34fe
Showing
3 changed files
with
66 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
typo3/sysext/frontend/Classes/Middleware/ContentLengthResponseHeader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace TYPO3\CMS\Frontend\Middleware; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use TYPO3\CMS\Core\Http\NullResponse; | ||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; | ||
|
||
/** | ||
* Send content-length header. | ||
* Notice that all HTML content outside the length of the content-length header will be cut off! | ||
* Therefore content of unknown length from included PHP-scripts and if admin users are logged | ||
* in (admin panel might show...) or if debug mode is turned on, we disable it! | ||
* | ||
* @internal | ||
*/ | ||
class ContentLengthResponseHeader implements MiddlewareInterface | ||
{ | ||
|
||
/** | ||
* Adds the content length | ||
* | ||
* @param ServerRequestInterface $request | ||
* @param RequestHandlerInterface $handler | ||
* @return ResponseInterface | ||
*/ | ||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
$response = $handler->handle($request); | ||
if ( | ||
!($response instanceof NullResponse) | ||
&& $GLOBALS['TSFE'] instanceof TypoScriptFrontendController | ||
&& $GLOBALS['TSFE']->isOutputting()) { | ||
if ( | ||
(!isset($GLOBALS['TSFE']->config['config']['enableContentLengthHeader']) || $GLOBALS['TSFE']->config['config']['enableContentLengthHeader']) | ||
&& !$GLOBALS['TSFE']->isBackendUserLoggedIn() && !$GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] | ||
&& !$GLOBALS['TSFE']->config['config']['debug'] && !$GLOBALS['TSFE']->doWorkspacePreview() | ||
) { | ||
$response = $response->withHeader('Content-Length', (string)$response->getBody()->getSize()); | ||
} | ||
} | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters