Skip to content

Commit

Permalink
[BUGFIX] Use correct content types in backend ajax and eID responses
Browse files Browse the repository at this point in the history
Due to the recent changes in the commit:
    e487cf5
    [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>
  • Loading branch information
bnf authored and lolli42 committed Feb 17, 2018
1 parent f0e1ca7 commit 2348992
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -714,10 +714,7 @@ public function saveFormAction(ServerRequestInterface $request): ResponseInterfa
}
}

if ($queryBuilder->execute() === 1) {
return new HtmlResponse($shortcutName);
}
return new HtmlResponse('failed');
return new HtmlResponse($queryBuilder->execute() === 1 ? $shortcutName : 'failed');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ protected function getPageRenderer()
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function ajaxExpandCollapse(ServerRequestInterface $request): ResponseInt
$this->init();
$tree = $this->foldertree->getBrowsableTree();
if ($this->foldertree->getAjaxStatus() === false) {
return new HtmlResponse('', 500);
return new JsonResponse(null, 500);
}
return new JsonResponse([$tree]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

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;
Expand Down Expand Up @@ -53,7 +52,7 @@ public function createAction(ServerRequestInterface $request): ResponseInterface
}
return new JsonResponse($data);
}
return new HtmlResponse('');
return new JsonResponse();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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;
Expand Down Expand Up @@ -71,7 +70,7 @@ public function getUsedLanguagesInPageAndColumn(ServerRequestInterface $request)
{
$params = $request->getQueryParams();
if (!isset($params['pageId'], $params['colPos'], $params['languageId'])) {
return new HtmlResponse('', 400);
return new JsonResponse(null, 400);
}

$pageId = (int)$params['pageId'];
Expand Down Expand Up @@ -123,7 +122,7 @@ public function getRecordLocalizeSummary(ServerRequestInterface $request): Respo
{
$params = $request->getQueryParams();
if (!isset($params['pageId'], $params['colPos'], $params['destLanguageId'], $params['languageId'])) {
return new HtmlResponse('', 400);
return new JsonResponse(null, 400);
}

$records = [];
Expand Down Expand Up @@ -158,11 +157,13 @@ public function localizeRecords(ServerRequestInterface $request): ResponseInterf
{
$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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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;
Expand Down Expand Up @@ -71,9 +71,9 @@ public function getWizardAction(ServerRequestInterface $request): ResponseInterf
'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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Controller/FileDumpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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;
Expand Down Expand Up @@ -88,7 +88,7 @@ public function dumpAction(ServerRequestInterface $request)
// @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);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions typo3/sysext/frontend/Classes/Controller/ShowImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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;
Expand Down Expand Up @@ -200,12 +200,14 @@ public function processRequest(ServerRequestInterface $request): ResponseInterfa
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

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;

Expand All @@ -35,14 +36,17 @@ public function processRequest(ServerRequestInterface $request): ResponseInterfa
$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();
$storage = StorageFactory::getStorage();
$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;
}
}
6 changes: 5 additions & 1 deletion typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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;
Expand Down Expand Up @@ -120,6 +121,9 @@ public function getRsaPublicKeyAjaxHandler(): ResponseInterface
])
);
}
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;
}
}
6 changes: 3 additions & 3 deletions typo3/sysext/taskcenter/Classes/TaskStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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
Expand All @@ -39,7 +39,7 @@ public function saveCollapseState(ServerRequestInterface $request): ResponseInte
$this->getBackendUserAuthentication()->uc['taskcenter']['states'][$item] = $state;
$this->getBackendUserAuthentication()->writeUC();

return new HtmlResponse('');
return new JsonResponse(null);
}

/**
Expand All @@ -60,7 +60,7 @@ public function saveSortingState(ServerRequestInterface $request): ResponseInter
$this->getBackendUserAuthentication()->uc['taskcenter']['sorting'] = serialize($sort);
$this->getBackendUserAuthentication()->writeUC();

return new HtmlResponse('');
return new JsonResponse(null);
}

/**
Expand Down

0 comments on commit 2348992

Please sign in to comment.