Commit 3a6c6ee3 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[BUGFIX] Catch ImmediateResponseException in Application->handle()

When TYPO3 is 'natively' called by a web server call, the
main application entry point is AbstractApplication run().

When using a PSR-15 from within some other application,
a request should be hand over to Application->handle(),
expecting a response object.

Now we have that ImmediateResponseException thrown by TYPO3
at some places.

ImmediateResponseException is only caught within run(), not
within handle(). A PSR-15 call to handle() will thus not
catch ImmediateResponseException, it bubbles up to the
calling application.

PSR-15 section 1.4 of https://www.php-fig.org/psr/psr-15/:
"It is RECOMMENDED that any application using middleware
includes a component that catches exceptions and converts
them into responses."

The patch changes AbstractApplication to follow this:
The ImmediateResponseException is a TYPO3 internal management
exception, a calling application should never need to deal
with it, but can expect to receive a response object instead.

Change-Id: I2857efd2b575a9b324d3d7a23df0bca5763a8839
Resolves: #96099
Releases: master, 11.5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72321

Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 5d65bec7
......@@ -82,7 +82,12 @@ abstract class AbstractApplication implements ApplicationInterface, RequestHandl
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
return $this->requestHandler->handle($request);
try {
$response = $this->requestHandler->handle($request);
} catch (ImmediateResponseException $exception) {
$response = $exception->getResponse();
}
return $response;
}
/**
......@@ -92,18 +97,11 @@ abstract class AbstractApplication implements ApplicationInterface, RequestHandl
*/
final public function run(callable $execute = null)
{
try {
$response = $this->handle(
ServerRequestFactory::fromGlobals()
);
if ($execute !== null) {
trigger_error('Custom execution of Application code will be removed in TYPO3 v12.0, use PSR-15 Middlewares instead.', E_USER_DEPRECATED);
$execute();
}
} catch (ImmediateResponseException $exception) {
$response = $exception->getResponse();
$response = $this->handle(ServerRequestFactory::fromGlobals());
if ($execute !== null) {
trigger_error('Custom execution of Application code will be removed in TYPO3 v12.0, use PSR-15 Middlewares instead.', E_USER_DEPRECATED);
$execute();
}
$this->sendResponse($response);
}
}
Markdown is supported
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