[FEATURE] Add stdWrap to config.additionalHeaders 42/50142/10
authorPhilipp Gampe <philipp.gampe@typo3.org>
Sat, 5 Nov 2016 18:13:10 +0000 (19:13 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Mon, 14 Aug 2017 13:27:59 +0000 (15:27 +0200)
Add stdWrap to the elements header, replace and httpResponseCode.

Resolves: #23494
Related: #56236
Releases: master
Change-Id: I3adbb63ec66097775c041a3a18299ad48f6df7aa
Reviewed-on: https://review.typo3.org/50142
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Reviewed-by: Henning Liebe <h.liebe@neusta.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-23494-AddStdWrapToConfigadditionalHeaders.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/t3editor/Resources/Private/tsref.xml

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-23494-AddStdWrapToConfigadditionalHeaders.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-23494-AddStdWrapToConfigadditionalHeaders.rst
new file mode 100644 (file)
index 0000000..6cb9bf6
--- /dev/null
@@ -0,0 +1,27 @@
+.. include:: ../../Includes.txt
+
+=========================================================
+Feature: #23494 - Add stdWrap to config.additionalHeaders
+=========================================================
+
+See :issue:`23494`
+
+Description
+===========
+
+Add stdWrap to the elements of the additionalHeaders array. This gives full control over sending an HTTP header.
+
+.. code-block:: typoscript
+
+       config.additionalHeaders {
+         10.header = foo:
+         10.header.dataWrap = |{page:uid}
+       }
+
+
+Impact
+======
+
+Allow to use stdWrap on the elements `header`, `replace` and `httpResponseCode`. Empty headers will be skipped now.
+
+.. index:: TypoScript
index 5b0ecdc..1bc5334 100644 (file)
@@ -3506,17 +3506,7 @@ class TypoScriptFrontendController
             $this->sendCacheHeaders();
         }
         // Set headers, if any
-        if (is_array($this->config['config']['additionalHeaders.'])) {
-            ksort($this->config['config']['additionalHeaders.']);
-            foreach ($this->config['config']['additionalHeaders.'] as $options) {
-                header(
-                    trim($options['header']),
-                    // "replace existing headers" is turned on by default, unless turned off
-                    ($options['replace'] !== '0'),
-                    ((int)$options['httpResponseCode'] ?: null)
-                );
-            }
-        }
+        $this->sendAdditionalHeaders();
         // Send appropriate status code in case of temporary content
         if ($this->tempContent) {
             $this->addTempContentHttpHeaders();
@@ -4571,6 +4561,47 @@ class TypoScriptFrontendController
     }
 
     /**
+     * Send additional headers from config.additionalHeaders
+     *
+     * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::processOutput()
+     */
+    protected function sendAdditionalHeaders()
+    {
+        if (!isset($this->config['config']['additionalHeaders.'])) {
+            return;
+        }
+        ksort($this->config['config']['additionalHeaders.']);
+        foreach ($this->config['config']['additionalHeaders.'] as $options) {
+            if (!is_array($options)) {
+                continue;
+            }
+            $header = $options['header'] ?? '';
+            $header = isset($options['header.'])
+                ? $this->cObj->stdWrap(trim($header), $options['header.'])
+                : trim($header);
+            if ($header === '') {
+                continue;
+            }
+            $replace = $options['replace'] ?? '';
+            $replace = isset($options['replace.'])
+                ? $this->cObj->stdWrap($replace, $options['replace.'])
+                : $replace;
+            $httpResponseCode = $options['httpResponseCode'] ?? '';
+            $httpResponseCode = isset($options['httpResponseCode.'])
+                ? $this->cObj->stdWrap($httpResponseCode, $options['httpResponseCode.'])
+                : $httpResponseCode;
+            $httpResponseCode = (int)$httpResponseCode;
+
+            header(
+                $header,
+                // "replace existing headers" is turned on by default, unless turned off
+                $replace !== '0',
+                $httpResponseCode ?: null
+            );
+        }
+    }
+
+    /**
      * Returns the current BE user.
      *
      * @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
index a17cf51..69ecad8 100644 (file)
@@ -207,19 +207,33 @@ Note: If you're working on a server where you have both internal and external ac
                        <default><![CDATA[
 ]]></default>
                </property>
-               <property name="additionalHeaders" type="string">
-                       <description><![CDATA[strings divided by "|"
-      This is additional headers. You separate each header by a vertical line "|". ┬áNormally TYPO3 does not send any headers with the Header()-function in PHP.
+               <property name="additionalHeaders" type="additionalHeadersArray">
+                       <description><![CDATA[This property can be used to define additional HTTP headers.
 
-Examples:
-Content-Type: text/vnd.wap.wml
-(this will sent a content-header for a WAP-site)
+For each numeric index, there are the following sub-properties:
+
+header: The header string.
+
+replace: Optional. If set, previous headers with the same name are replaced with the current one. Default is "1".
+
+httpResponseCode: Optional. HTTP status code as an integer.
 
-Content-Type: image/gif | Expires: Mon, 26 Jul 1997 05:00:00 GMT
-(this will sent a content-header for a GIF-file and a Expires header)
+Example:
+
+config.additionalHeaders {
+   10 {
+      # The header string
+      header = WWW-Authenticate: Negotiate
 
-Location: www.typo3.org
-(This redirects the page to www.typo3.org)]]></description>
+      # Do not replace previous headers with the same name.
+      replace = 0
+
+      # Force a 401 HTTP response code
+      httpResponseCode = 401
+   }
+   # Always set cache headers to private, overwriting the default TYPO3 Cache-control header
+   20.header = Cache-control: Private
+}]]></description>
                        <default><![CDATA[
 ]]></default>
                </property>
@@ -6998,4 +7012,48 @@ The userfunction must return an <A>-tag.]]></description>
 ]]></description>
                </property>
        </type>
+       <type id="additionalHeadersArray" extends="array">
+               <property name="10" type="additionalHeadersItem">
+                       <description><![CDATA[Defines a header.
+
+Must at least contain the header property.]]></description>
+                       <default><![CDATA[]]></default>
+               </property>
+               <property name="20" type="additionalHeadersItem">
+                       <description><![CDATA[Defines a header.
+
+Must at least contain the header property.]]></description>
+                       <default><![CDATA[]]></default>
+               </property>
+               <property name="30" type="additionalHeadersItem">
+                       <description><![CDATA[Defines a header.
+
+Must at least contain the header property.]]></description>
+                       <default><![CDATA[]]></default>
+               </property>
+               <property name="40" type="additionalHeadersItem">
+                       <description><![CDATA[Defines a header.
+
+Must at least contain the header property.]]></description>
+                       <default><![CDATA[]]></default>
+               </property>
+       </type>
+       <type id="additionalHeadersItem">
+               <property name="header" type="stdWrap">
+                       <description><![CDATA[The header string]]></description>
+                       <default><![CDATA[]]></default>
+               </property>
+               <property name="replace" type="stdWrap">
+                       <description><![CDATA[Optional.
+
+If set, previous headers with the same name are replaced with the current one.
+
+Default is "1".]]></description>
+                       <default><![CDATA[1]]></default>
+               </property>
+               <property name="httpResponseCode" type="stdWrap">
+                       <description><![CDATA[Optional. HTTP status code as an integer.]]></description>
+                       <default><![CDATA[]]></default>
+               </property>
+       </type>
 </tsRef>