Commit 88122436 authored by Benni Mack's avatar Benni Mack Committed by Oliver Hader
Browse files

[BUGFIX] Make external page error handling work again

In recent TYPO3 v11.5.x versions, the error handling for Frontend
pages did cache the external PSR-7 Response (by guzzle) in the
pages cache. However, if the error page was fetched the second time,
the Response object from the cache did not have a valid stream anymore,
thus resulting in an array.

This change now caches the body + headers for the page (still, only
when a 200 response code was returned), and re-builds a clean Response
object.

Resolves: #95940
Related: #95586
Related: #94402
Releases: master
Change-Id: I27aaffe8acda275fd3450f9479e19a3f21d22df6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72184

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
parent 08669c3f
...@@ -26,6 +26,8 @@ use TYPO3\CMS\Core\Configuration\Features; ...@@ -26,6 +26,8 @@ use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\RequestFactory; use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Core\Http\Uri; use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\LinkHandling\LinkService; use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException; use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException;
...@@ -138,10 +140,9 @@ class PageContentErrorHandler implements PageErrorHandlerInterface ...@@ -138,10 +140,9 @@ class PageContentErrorHandler implements PageErrorHandlerInterface
protected function cachePageRequest(string $resolvedUrl, int $pageId, callable $fetcher): ResponseInterface protected function cachePageRequest(string $resolvedUrl, int $pageId, callable $fetcher): ResponseInterface
{ {
$cacheIdentifier = 'errorPage_' . md5($resolvedUrl); $cacheIdentifier = 'errorPage_' . md5($resolvedUrl);
/** @var ResponseInterface $response */ $responseData = $this->cache->get($cacheIdentifier);
$response = $this->cache->get($cacheIdentifier);
if (!$response) { if (!is_array($responseData)) {
/** @var ResponseInterface $response */ /** @var ResponseInterface $response */
$response = $fetcher(); $response = $fetcher();
$cacheTags = []; $cacheTags = [];
...@@ -151,8 +152,23 @@ class PageContentErrorHandler implements PageErrorHandlerInterface ...@@ -151,8 +152,23 @@ class PageContentErrorHandler implements PageErrorHandlerInterface
// Cache Tag "pageId_" ensures, cache is purged when content of 404 page changes // Cache Tag "pageId_" ensures, cache is purged when content of 404 page changes
$cacheTags[] = 'pageId_' . $pageId; $cacheTags[] = 'pageId_' . $pageId;
} }
$this->cache->set($cacheIdentifier, $response, $cacheTags); $responseData = [
'headers' => $response->getHeaders(),
'body' => $response->getBody()->getContents(),
'reasonPhrase' => $response->getReasonPhrase(),
];
$this->cache->set($cacheIdentifier, $responseData, $cacheTags);
} }
} else {
$body = new Stream('php://temp', 'wb+');
$body->write($responseData['body'] ?? '');
$body->rewind();
$response = new Response(
$body,
200,
$responseData['headers'] ?? [],
$responseData['reasonPhrase'] ?? ''
);
} }
return $response; return $response;
......
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