[TASK] Centralize sending HTTP headers in TSFE 40/57940/3
authorBenni Mack <benni@typo3.org>
Fri, 17 Aug 2018 05:37:29 +0000 (07:37 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Fri, 17 Aug 2018 08:10:08 +0000 (10:10 +0200)
This patch marks the last change of reordering
sending HTTP response headers via TSFE via
header(), sending all headers within TSFE->processOutput().

Once centralized, the headers can now put into a
PSR-7 response object, if wanted.

Resolves: #85883
Releases: master
Change-Id: I4c9289a43748f02fb571421e34aa7f66ce34cc4a
Reviewed-on: https://review.typo3.org/57940
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

index 23ab10d..b674128 100644 (file)
@@ -3824,7 +3824,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
      * Process the output before it's actually outputted. Sends headers also.
      *
      * This includes substituting the "username" comment, sending additional headers
-     * (as defined in the TypoScript "config.additionalheaders" object), XHTML cleaning content (if configured)
+     * (as defined in the TypoScript "config.additionalHeaders" object), XHTML cleaning content (if configured)
      * Works on $this->content.
      */
     public function processOutput()
@@ -3846,8 +3846,16 @@ class TypoScriptFrontendController implements LoggerAwareInterface
                 header($header . ': ' . $value);
             }
         }
-        // Set headers, if any
-        $this->sendAdditionalHeaders();
+        // Set additional headers if any have been configured via TypoScript
+        $additionalHeaders = $this->getAdditionalHeaders();
+        foreach ($additionalHeaders as $headerConfig) {
+            header(
+                $headerConfig['header'],
+                // "replace existing headers" is turned on by default, unless turned off
+                $headerConfig['replace'],
+                $headerConfig['statusCode']
+            );
+        }
         // Send appropriate status code in case of temporary content
         if ($this->tempContent) {
             header('HTTP/1.0 503 Service unavailable');
@@ -4891,13 +4899,14 @@ class TypoScriptFrontendController implements LoggerAwareInterface
     /**
      * Send additional headers from config.additionalHeaders
      *
-     * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::processOutput()
+     * @see processOutput()
      */
-    protected function sendAdditionalHeaders()
+    protected function getAdditionalHeaders(): array
     {
         if (!isset($this->config['config']['additionalHeaders.'])) {
-            return;
+            return [];
         }
+        $additionalHeaders = [];
         ksort($this->config['config']['additionalHeaders.']);
         foreach ($this->config['config']['additionalHeaders.'] as $options) {
             if (!is_array($options)) {
@@ -4920,13 +4929,14 @@ class TypoScriptFrontendController implements LoggerAwareInterface
                 : $httpResponseCode;
             $httpResponseCode = (int)$httpResponseCode;
 
-            header(
-                $header,
+            $additionalHeaders[] = [
+                'header' => $header,
                 // "replace existing headers" is turned on by default, unless turned off
-                $replace !== '0',
-                $httpResponseCode ?: null
-            );
+                'replace' => $replace !== '0',
+                'statusCode' => $httpResponseCode ?: null
+            ];
         }
+        return $additionalHeaders;
     }
 
     /**