Skip to content

Commit

Permalink
Merge pull request #9 from andersundsehr/bugfix/originalRequestUri
Browse files Browse the repository at this point in the history
🐛 fix originalRequestUri
  • Loading branch information
Kanti authored Nov 19, 2024
2 parents 9326482 + 1d6f50d commit 8fe8d4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
18 changes: 7 additions & 11 deletions Classes/Middleware/InternalSsiRedirectMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) ?: '<error>EXT:ssi_include error path:' . $absolutePath . '</error>');
}

return $handler->handle($request);
Expand Down
7 changes: 4 additions & 3 deletions Classes/ViewHelpers/RenderIncludeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 '<esi:include src="' . $reqUrl . '" />';
}
Expand All @@ -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'];
}

Expand Down

0 comments on commit 8fe8d4d

Please sign in to comment.