From a7d63adc3b4d568dee86fe9267b1b069c089269f Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Tue, 3 Oct 2017 01:34:02 +0200
Subject: [PATCH] [BUGFIX] Set content-length header to the end of output

Resolves: #76100
Resolves: #65719
Releases: master, 8.7
Change-Id: I2e389dd6ecb497a164a457230f106a64373c1907
Reviewed-on: https://review.typo3.org/54268
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
---
 .../Controller/TypoScriptFrontendController.php       | 11 -----------
 typo3/sysext/frontend/Classes/Http/RequestHandler.php | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
index 54ebe583480e..8a6c5c0dcaab 100644
--- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
+++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
@@ -3539,17 +3539,6 @@ class TypoScriptFrontendController implements LoggerAwareInterface
                 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
             }
         }
-        // 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!
-        if (
-            (!isset($this->config['config']['enableContentLengthHeader']) || $this->config['config']['enableContentLengthHeader'])
-            && !$this->beUserLogin && !$GLOBALS['TYPO3_CONF_VARS']['FE']['debug']
-            && !$this->config['config']['debug'] && !$this->doWorkspacePreview()
-        ) {
-            header('Content-Length: ' . strlen($this->content));
-        }
     }
 
     /**
diff --git a/typo3/sysext/frontend/Classes/Http/RequestHandler.php b/typo3/sysext/frontend/Classes/Http/RequestHandler.php
index f5ea643fc2a2..47e93efc7301 100644
--- a/typo3/sysext/frontend/Classes/Http/RequestHandler.php
+++ b/typo3/sysext/frontend/Classes/Http/RequestHandler.php
@@ -263,6 +263,17 @@ class RequestHandler implements RequestHandlerInterface
         }
 
         if ($sendTSFEContent) {
+            // 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!
+            if (
+                (!isset($this->controller->config['config']['enableContentLengthHeader']) || $this->controller->config['config']['enableContentLengthHeader'])
+                && !$this->controller->beUserLogin && !$GLOBALS['TYPO3_CONF_VARS']['FE']['debug']
+                && !$this->controller->config['config']['debug'] && !$this->controller->doWorkspacePreview()
+            ) {
+                header('Content-Length: ' . strlen($this->controller->content));
+            }
             $response->getBody()->write($this->controller->content);
         }
         GeneralUtility::makeInstance(LogManager::class)
-- 
GitLab