[TASK] Use PSR-7 Response objects for external URL redirects 86/55586/3
authorBenjamin Franzke <bfr@qbus.de>
Tue, 6 Feb 2018 22:34:20 +0000 (23:34 +0100)
committerBenni Mack <benni@typo3.org>
Thu, 8 Feb 2018 21:15:29 +0000 (22:15 +0100)
Instead of immediately exiting, allow to post-process the response
through the middleware chain.

Change-Id: Icfb47f7cd84c80201a3c3b9927267e8b8aaef440
Releases: master
Resolves: #83794
Reviewed-on: https://review.typo3.org/55586
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Classes/Http/RequestHandler.php
typo3/sysext/frontend/Classes/Page/ExternalPageUrlHandler.php

index d580ccf..5e860d4 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Frontend\Controller;
  */
 
 use Doctrine\DBAL\Exception\ConnectionException;
+use Psr\Http\Message\ResponseInterface;
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
 use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
@@ -2767,16 +2768,22 @@ class TypoScriptFrontendController implements LoggerAwareInterface
      * the redirectUrl propert is not empty, the user will be redirected to this URL.
      *
      * @internal Should be called by the FrontendRequestHandler only.
+     * @return ResponseInterface|null
      */
     public function redirectToExternalUrl()
     {
         foreach ($this->activeUrlHandlers as $redirectHandler) {
-            $redirectHandler->handle();
+            $response = $redirectHandler->handle();
+            if ($response instanceof ResponseInterface) {
+                return $response;
+            }
         }
 
         if (!empty($this->activeUrlHandlers)) {
             throw new \RuntimeException('A URL handler is active but did not process the URL.', 1442305505);
         }
+
+        return null;
     }
 
     /**
index 3e9d914..7a5199a 100644 (file)
@@ -253,7 +253,11 @@ class RequestHandler implements RequestHandlerInterface, PsrRequestHandlerInterf
                 $response = $response->withHeader('X-TYPO3-Parsetime', $this->timeTracker->getParseTime() . 'ms');
             }
         }
-        $this->controller->redirectToExternalUrl();
+        $redirectResponse = $this->controller->redirectToExternalUrl();
+        if ($redirectResponse instanceof ResponseInterface) {
+            return $redirectResponse;
+        }
+
         // Preview info
         $this->controller->previewInfo();
         // Hook for end-of-frontend
index 7aeea85..9eb8136 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\Frontend\Page;
 
 /*
@@ -14,7 +15,9 @@ namespace TYPO3\CMS\Frontend\Page;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Utility\HttpUtility;
+use Psr\Http\Message\ResponseInterface;
+use TYPO3\CMS\Core\Http\RedirectResponse;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
  * Handles the redirection for external URL pages.
@@ -31,7 +34,7 @@ class ExternalPageUrlHandler implements \TYPO3\CMS\Frontend\Http\UrlHandlerInter
      *
      * @return bool
      */
-    public function canHandleCurrentUrl()
+    public function canHandleCurrentUrl(): bool
     {
         $tsfe = $this->getTypoScriptFrontendController();
 
@@ -49,15 +52,15 @@ class ExternalPageUrlHandler implements \TYPO3\CMS\Frontend\Http\UrlHandlerInter
     /**
      * Redirects the user to the detected external URL.
      */
-    public function handle()
+    public function handle(): ResponseInterface
     {
-        HttpUtility::redirect($this->externalUrl, HttpUtility::HTTP_STATUS_303);
+        return new RedirectResponse($this->externalUrl, 303);
     }
 
     /**
-     * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
+     * @return TypoScriptFrontendController
      */
-    protected function getTypoScriptFrontendController()
+    protected function getTypoScriptFrontendController(): TypoScriptFrontendController
     {
         return $GLOBALS['TSFE'];
     }