From 1d6f50dcac8b1f1720989515be4304f41dc59039 Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Mon, 18 Nov 2024 17:54:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20originalRequestUri?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InternalSsiRedirectMiddleware.php | 18 +++++++----------- .../ViewHelpers/RenderIncludeViewHelper.php | 7 ++++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Classes/Middleware/InternalSsiRedirectMiddleware.php b/Classes/Middleware/InternalSsiRedirectMiddleware.php index 35c23d7..1d860dd 100644 --- a/Classes/Middleware/InternalSsiRedirectMiddleware.php +++ b/Classes/Middleware/InternalSsiRedirectMiddleware.php @@ -14,14 +14,10 @@ class InternalSsiRedirectMiddleware implements MiddlewareInterface { - public static int $SSI_CONTEXT = 0; - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { if (isset($request->getQueryParams()['ssi_include'])) { - self::$SSI_CONTEXT = 1; - - $originalRequestPath = $request->getQueryParams()['originalRequestPath'] ?? ''; + $originalRequestUri = $request->getQueryParams()['originalRequestUri'] ?? ''; $ssiInclude = $request->getQueryParams()['ssi_include']; if (!preg_match('/^(\w+)$/', (string) $ssiInclude)) { return new HtmlResponse('ssi_include invalid', 400); @@ -31,14 +27,14 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $absolutePath = Environment::getPublicPath() . $cacheFileName; if (!file_exists($absolutePath)) { // ignore response use the content of the file: - $handler->handle( - $request - ->withAttribute('noCache', true) - ->withUri($request->getUri()->withPath($originalRequestPath)) - ); + $subRequest = $request + ->withAttribute('noCache', true) + ->withUri($request->getUri()->withPath($originalRequestUri)->withQuery('')) + ->withQueryParams([]); + $handler->handle($subRequest); } - return new HtmlResponse(file_get_contents($absolutePath) ?: ''); + return new HtmlResponse(file_get_contents($absolutePath) ?: 'EXT:ssi_include error path:' . $absolutePath . ''); } return $handler->handle($request); diff --git a/Classes/ViewHelpers/RenderIncludeViewHelper.php b/Classes/ViewHelpers/RenderIncludeViewHelper.php index 519ce83..bfa96d7 100644 --- a/Classes/ViewHelpers/RenderIncludeViewHelper.php +++ b/Classes/ViewHelpers/RenderIncludeViewHelper.php @@ -53,7 +53,8 @@ public static function renderStatic(array $arguments, Closure $renderChildrenClo $filename = static::getSiteName() . '_' . static::getLangauge() . '_' . $name; $reverseProxyPrefix = '/' . trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyPrefix'] ?? '', '/') . '/'; - $basePath = rtrim($reverseProxyPrefix, '/') . self::SSI_INCLUDE_DIR . $filename; + $basePath = self::SSI_INCLUDE_DIR . $filename; + $includePath = rtrim($reverseProxyPrefix, '/') . $basePath; $absolutePath = Environment::getPublicPath() . $basePath; if (self::shouldRenderFile($absolutePath, $arguments['cacheLifeTime'])) { $html = parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext); @@ -72,7 +73,7 @@ public static function renderStatic(array $arguments, Closure $renderChildrenClo } $method = self::getExtensionConfiguration()->get('ssi_include', 'method') ?: self::METHOD_SSI; - $reqUrl = $basePath . '?ssi_include=' . $filename . '&originalRequestUri=' . urlencode((string) $_SERVER['REQUEST_URI']); + $reqUrl = $includePath . '?ssi_include=' . $filename . '&originalRequestUri=' . urlencode((string)GeneralUtility::getIndpEnv('REQUEST_URI')); if ($method === self::METHOD_ESI) { return ''; } @@ -99,7 +100,7 @@ private static function shouldRenderFile(string $absolutePath, int $cacheLifeTim */ private static function validateName(array $arguments): string { - if (ctype_alnum((string) $arguments['name'])) { + if (ctype_alnum((string)$arguments['name'])) { return $arguments['name']; }