Skip to content
Snippets Groups Projects
Commit 0d822ba4 authored by Markus Klein's avatar Markus Klein Committed by Benni Mack
Browse files

[BUGFIX] Ensure PageContentErrorHandler content is served correctly

Use only the body and the content-type header of the internal
sub-request. Everything else of the sub-request can be discarded.

Resolves: #91582
Related: #81644
Releases: master, 10.4
Change-Id: I393acb340c04b3c7aa0cde1e1de1df9fcc92ca7a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64672


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarJohannes Kasberger <johannes.kasberger@reelworx.at>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarJohannes Kasberger <johannes.kasberger@reelworx.at>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
parent f1ad8077
No related merge requests found
......@@ -22,6 +22,7 @@ use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException;
use TYPO3\CMS\Core\Site\Entity\Site;
......@@ -75,14 +76,17 @@ class PageContentErrorHandler implements PageErrorHandlerInterface
$content = null;
if ($resolvedUrl !== (string)$request->getUri()) {
try {
$response = GeneralUtility::makeInstance(RequestFactory::class)->request($resolvedUrl, 'GET');
$subResponse = GeneralUtility::makeInstance(RequestFactory::class)->request($resolvedUrl, 'GET');
} catch (\Exception $e) {
throw new \RuntimeException('Error handler could not fetch error page "' . $resolvedUrl . '", reason: ' . $e->getMessage(), 1544172838);
}
if ($response->getStatusCode() >= 300) {
throw new \RuntimeException('Error handler could not fetch error page "' . $resolvedUrl . '", status code: ' . $response->getStatusCode(), 1544172839);
if ($subResponse->getStatusCode() >= 300) {
throw new \RuntimeException('Error handler could not fetch error page "' . $resolvedUrl . '", status code: ' . $subResponse->getStatusCode(), 1544172839);
}
return $response->withStatus($this->statusCode);
// create new response object and re-use only the body and the content-type of the sub-request
return new Response($subResponse->getBody(), $this->statusCode, [
'Content-Type' => $subResponse->getHeader('Content-Type')
]);
}
$content = 'The error page could not be resolved, as the error page itself is not accessible';
} catch (InvalidRouteArgumentsException | SiteNotFoundException $e) {
......
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