Skip to content

Commit

Permalink
Adjust include rendering, add global ssi context indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
aus-DominikHalle committed Oct 7, 2024
1 parent 4b80639 commit 322ce99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Classes/Middleware/InternalSsiRedirectMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@

class InternalSsiRedirectMiddleware implements MiddlewareInterface
{
public static int $SSI_CONTEXT = 0;

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (isset($request->getQueryParams()['ssi_include'])) {
putenv('SSI_CONTEXT=1');
self::$SSI_CONTEXT = 1;

$originalRequestPath = $request->getQueryParams()['originalRequestPath'] ?? '';
$ssiInclude = $request->getQueryParams()['ssi_include'];
if (!preg_match('/^(\w+)$/', (string) $ssiInclude)) {
return new HtmlResponse('ssi_include invalid', 400);
Expand All @@ -27,7 +31,11 @@ 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));
$handler->handle(
$request
->withAttribute('noCache', true)
->withUri($request->getUri()->withPath($originalRequestPath))
);
}

return new HtmlResponse(file_get_contents($absolutePath) ?: '');
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/RenderIncludeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function renderStatic(array $arguments, Closure $renderChildrenClo
}

$method = self::getExtensionConfiguration()->get('ssi_include', 'method') ?: self::METHOD_SSI;
$reqUrl = $basePath . '?ssi_include=' . $filename;
$reqUrl = $basePath . '?ssi_include=' . $filename . '&originalRequestUri=' . urlencode($_SERVER['REQUEST_URI']);
if ($method === self::METHOD_ESI) {
return '<esi:include src="' . $reqUrl . '" />';
}
Expand Down

0 comments on commit 322ce99

Please sign in to comment.