Skip to content

Commit 322ce99

Browse files
Adjust include rendering, add global ssi context indicator
1 parent 4b80639 commit 322ce99

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Classes/Middleware/InternalSsiRedirectMiddleware.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
class InternalSsiRedirectMiddleware implements MiddlewareInterface
1616
{
17+
public static int $SSI_CONTEXT = 0;
18+
1719
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
1820
{
1921
if (isset($request->getQueryParams()['ssi_include'])) {
20-
putenv('SSI_CONTEXT=1');
22+
self::$SSI_CONTEXT = 1;
23+
24+
$originalRequestPath = $request->getQueryParams()['originalRequestPath'] ?? '';
2125
$ssiInclude = $request->getQueryParams()['ssi_include'];
2226
if (!preg_match('/^(\w+)$/', (string) $ssiInclude)) {
2327
return new HtmlResponse('ssi_include invalid', 400);
@@ -27,7 +31,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
2731
$absolutePath = Environment::getPublicPath() . $cacheFileName;
2832
if (!file_exists($absolutePath)) {
2933
// ignore response use the content of the file:
30-
$handler->handle($request->withAttribute('noCache', true));
34+
$handler->handle(
35+
$request
36+
->withAttribute('noCache', true)
37+
->withUri($request->getUri()->withPath($originalRequestPath))
38+
);
3139
}
3240

3341
return new HtmlResponse(file_get_contents($absolutePath) ?: '');

Classes/ViewHelpers/RenderIncludeViewHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function renderStatic(array $arguments, Closure $renderChildrenClo
7171
}
7272

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

0 commit comments

Comments
 (0)