[BUGFIX] Use correct content types in backend ajax and eID responses 66/55766/6
authorBenjamin Franzke <bfr@qbus.de>
Fri, 16 Feb 2018 19:38:44 +0000 (20:38 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 17 Feb 2018 19:30:46 +0000 (20:30 +0100)
Due to the recent changes in the commit:
    e487cf526980570aa8f7a92d170bf439637c5972
    [TASK] Create own response instance in controller actions

..ajax routes and eID handlers that used a *pre-generated* Response
object (from the RequestHandler) now return different Content-Type
headers than before.

For backend ajax request applicaton/json was set by default,
for eID scripts no Content-Type was set (by default).

Change these controllers to use JsonResponse or a plain Response
to reflect the previous state..

The changes in this commit were intended to be squashed into the
mentioned commit – but this commit was too late. Therefore other (a bit)
unrelated optimizations to changes that patch made are included.

Change-Id: Icfdcd02d353dfaf48ad959c50be4802349eaaacd
Releases: master
Resolves: #83946
Related: #83939
Reviewed-on: https://review.typo3.org/55766
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
13 files changed:
typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php
typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php
typo3/sysext/backend/Classes/Controller/ContextHelpAjaxController.php
typo3/sysext/backend/Classes/Controller/File/FileController.php
typo3/sysext/backend/Classes/Controller/FileSystemNavigationFrameController.php
typo3/sysext/backend/Classes/Controller/OnlineMediaController.php
typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php
typo3/sysext/backend/Classes/Form/Wizard/ImageManipulationWizard.php
typo3/sysext/core/Classes/Controller/FileDumpController.php
typo3/sysext/frontend/Classes/Controller/ShowImageController.php
typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php
typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php
typo3/sysext/taskcenter/Classes/TaskStatus.php

index 6c3332d..178163c 100644 (file)
@@ -714,10 +714,7 @@ class ShortcutToolbarItem implements ToolbarItemInterface
             }
         }
 
-        if ($queryBuilder->execute() === 1) {
-            return new HtmlResponse($shortcutName);
-        }
-        return new HtmlResponse('failed');
+        return new HtmlResponse($queryBuilder->execute() === 1 ? $shortcutName : 'failed');
     }
 
     /**
index c4eed8b..3669eb8 100644 (file)
@@ -415,8 +415,7 @@ class SystemInformationToolbarItem implements ToolbarItemInterface
     protected function getSignalSlotDispatcher()
     {
         if (!isset($this->signalSlotDispatcher)) {
-            $this->signalSlotDispatcher = GeneralUtility::makeInstance(ObjectManager::class)
-                ->get(Dispatcher::class);
+            $this->signalSlotDispatcher = GeneralUtility::makeInstance(ObjectManager::class)->get(Dispatcher::class);
         }
         return $this->signalSlotDispatcher;
     }
index e1af5cd..5114c7a 100644 (file)
@@ -37,7 +37,7 @@ class ContextHelpAjaxController
     public function getHelpAction(ServerRequestInterface $request): ResponseInterface
     {
         $params = $request->getParsedBody()['params'] ?? $request->getQueryParams()['params'];
-        if ($params['action'] !== 'getContextHelp') {
+        if (($params['action'] ?? '') !== 'getContextHelp') {
             throw new \RuntimeException('Action must be set to "getContextHelp"', 1518787887);
         }
         $result = $this->getContextHelp($params['table'], $params['field']);
index 372ff42..d62f3d1 100644 (file)
@@ -176,7 +176,7 @@ class FileController
         BackendUtility::setUpdateSignal('updateFolderTree');
 
         // go and edit the new created file
-        if ($request->getParsedBody()['edit']) {
+        if ($request->getParsedBody()['edit'] ?? '') {
             /** @var \TYPO3\CMS\Core\Resource\File $file */
             $file = $this->fileData['newfile'][0];
             $properties = $file->getProperties();
index 785fee5..905dad7 100644 (file)
@@ -231,7 +231,7 @@ class FileSystemNavigationFrameController
         $this->init();
         $tree = $this->foldertree->getBrowsableTree();
         if ($this->foldertree->getAjaxStatus() === false) {
-            return new HtmlResponse('', 500);
+            return new JsonResponse(null, 500);
         }
         return new JsonResponse([$tree]);
     }
index a61cd12..02a6421 100644 (file)
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Backend\Controller;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Http\HtmlResponse;
 use TYPO3\CMS\Core\Http\JsonResponse;
 use TYPO3\CMS\Core\Http\RedirectResponse;
 use TYPO3\CMS\Core\Localization\LanguageService;
@@ -53,7 +52,7 @@ class OnlineMediaController
             }
             return new JsonResponse($data);
         }
-        return new HtmlResponse('');
+        return new JsonResponse();
     }
 
     /**
index 8650faa..bc86f0a 100644 (file)
@@ -20,7 +20,6 @@ use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
 use TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
-use TYPO3\CMS\Core\Http\HtmlResponse;
 use TYPO3\CMS\Core\Http\JsonResponse;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
@@ -71,7 +70,7 @@ class LocalizationController
     {
         $params = $request->getQueryParams();
         if (!isset($params['pageId'], $params['colPos'], $params['languageId'])) {
-            return new HtmlResponse('', 400);
+            return new JsonResponse(null, 400);
         }
 
         $pageId = (int)$params['pageId'];
@@ -123,7 +122,7 @@ class LocalizationController
     {
         $params = $request->getQueryParams();
         if (!isset($params['pageId'], $params['colPos'], $params['destLanguageId'], $params['languageId'])) {
-            return new HtmlResponse('', 400);
+            return new JsonResponse(null, 400);
         }
 
         $records = [];
@@ -158,11 +157,13 @@ class LocalizationController
     {
         $params = $request->getQueryParams();
         if (!isset($params['pageId'], $params['srcLanguageId'], $params['destLanguageId'], $params['action'], $params['uidList'])) {
-            return new HtmlResponse('', 400);
+            return new JsonResponse(null, 400);
         }
 
         if ($params['action'] !== static::ACTION_COPY && $params['action'] !== static::ACTION_LOCALIZE) {
-            return new HtmlResponse('Invalid action "' . $params['action'] . '" called.', 400);
+            $response = new Response('php://temp', 400, ['Content-Type' => 'application/json; charset=utf-8']);
+            $response->getBody()->write('Invalid action "' . $params['action'] . '" called.');
+            return $response;
         }
 
         // Filter transmitted but invalid uids
index 69ce4d1..f4637fa 100644 (file)
@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Backend\Form\Wizard;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\JsonResponse;
 use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -71,9 +71,9 @@ class ImageManipulationWizard
                 'cropVariants' => $queryParams['cropVariants']
             ];
             $content = $this->templateView->renderSection('Main', $viewData);
-            return new HtmlResponse($content);
+            return new JsonResponse($content);
         }
-        return new HtmlResponse('', 403);
+        return new JsonResponse(null, 403);
     }
 
     /**
index f80f97c..cb60a19 100644 (file)
@@ -16,7 +16,7 @@ namespace TYPO3\CMS\Core\Controller;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\Response;
 use TYPO3\CMS\Core\Resource\Hook\FileDumpEIDHookInterface;
 use TYPO3\CMS\Core\Resource\ProcessedFileRepository;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
@@ -88,7 +88,7 @@ class FileDumpController
             // @todo Refactor FAL to not echo directly, but to implement a stream for output here and use response
             return null;
         }
-        return new HtmlResponse('', 403);
+        return (new Response)->withStatus(403);
     }
 
     /**
index 370988a..143f286 100644 (file)
@@ -17,7 +17,7 @@ namespace TYPO3\CMS\Frontend\Controller;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Exception;
-use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\Response;
 use TYPO3\CMS\Core\Resource\ProcessedFile;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -200,12 +200,14 @@ EOF;
         try {
             $this->initialize();
             $this->main();
-            return new HtmlResponse($this->content);
+            $response = new Response();
+            $response->getBody()->write($this->content);
+            return $response;
         } catch (\InvalidArgumentException $e) {
             // add a 410 "gone" if invalid parameters given
-            return new HtmlResponse('', 410);
+            return (new Response)->withStatus(410);
         } catch (Exception $e) {
-            return new HtmlResponse('', 404);
+            return (new Response)->withStatus(404);
         }
     }
 }
index 2fa83ac..3bb91ea 100644 (file)
@@ -16,7 +16,8 @@ namespace TYPO3\CMS\Rsaauth\Controller;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\JsonResponse;
+use TYPO3\CMS\Core\Http\Response;
 use TYPO3\CMS\Rsaauth\Backend\BackendFactory;
 use TYPO3\CMS\Rsaauth\Storage\StorageFactory;
 
@@ -35,7 +36,7 @@ class RsaPublicKeyGenerationController
         $backend = BackendFactory::getBackend();
         if ($backend === null) {
             // add a HTTP 500 error code, if an error occurred
-            return new HtmlResponse('', 500);
+            return new JsonResponse(null, 500);
         }
 
         $keyPair = $backend->createNewKeyPair();
@@ -43,6 +44,9 @@ class RsaPublicKeyGenerationController
         $storage->put($keyPair->getPrivateKey());
         session_commit();
         $content = $keyPair->getPublicKeyModulus() . ':' . sprintf('%x', $keyPair->getExponent()) . ':';
-        return new HtmlResponse($content);
+
+        $response = new Response('php://temp', 200, ['Content-Type' => 'application/json; charset=utf-8']);
+        $response->getBody()->write($content);
+        return $response;
     }
 }
index 5bb6dda..001ba3c 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Rsaauth;
 
 use Psr\Http\Message\ResponseInterface;
 use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\Response;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -120,6 +121,9 @@ class RsaEncryptionEncoder implements SingletonInterface
                 ])
             );
         }
-        return new HtmlResponse('No OpenSSL backend could be obtained for rsaauth.', 500);
+
+        $response = new Response('php://temp', 500, ['Content-Type' => 'application/json; charset=utf-8']);
+        $response->getBody()->write('No OpenSSL backend could be obtained for rsaauth.');
+        return $response;
     }
 }
index 20aa687..d67297e 100644 (file)
@@ -16,7 +16,7 @@ namespace TYPO3\CMS\Taskcenter;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\JsonResponse;
 
 /**
  * Status of tasks
@@ -39,7 +39,7 @@ class TaskStatus
         $this->getBackendUserAuthentication()->uc['taskcenter']['states'][$item] = $state;
         $this->getBackendUserAuthentication()->writeUC();
 
-        return new HtmlResponse('');
+        return new JsonResponse(null);
     }
 
     /**
@@ -60,7 +60,7 @@ class TaskStatus
         $this->getBackendUserAuthentication()->uc['taskcenter']['sorting'] = serialize($sort);
         $this->getBackendUserAuthentication()->writeUC();
 
-        return new HtmlResponse('');
+        return new JsonResponse(null);
     }
 
     /**