Commit 2348992f authored by Benjamin Franzke's avatar Benjamin Franzke Committed by Christian Kuhn
Browse files

[BUGFIX] Use correct content types in backend ajax and eID responses

Due to the recent changes in the commit:
    e487cf52
    [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: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent f0e1ca7f
......@@ -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');
}
/**
......
......@@ -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;
}
......
......@@ -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']);
......
......@@ -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();
......
......@@ -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]);
}
......
......@@ -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();
}
/**
......
......@@ -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
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
}
}
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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);
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment