Skip to content

Commit

Permalink
[BUGFIX] Proper checks for headless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
twoldanski authored and lukaszuznanski committed Dec 13, 2023
1 parent 426e3fe commit 23f3057
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Classes/Middleware/SiteBaseRedirectResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\Middleware;

use FriendsOfTYPO3\Headless\Utility\HeadlessMode;
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -22,6 +23,8 @@

class SiteBaseRedirectResolver extends \TYPO3\CMS\Frontend\Middleware\SiteBaseRedirectResolver
{
public function __construct(private readonly HeadlessMode $headlessMode) {}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = parent::process($request, $handler);
Expand All @@ -32,9 +35,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $response;
}

$siteConf = $site->getConfiguration();

if (!($siteConf['headless'] ?? false)) {
if (!$this->headlessMode->withRequest($request)->isEnabled()) {
return $response;
}

Expand Down
5 changes: 4 additions & 1 deletion Tests/Unit/Middleware/SiteBaseRedirectResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace FriendsOfTYPO3\Headless\Tests\Unit\Middleware;

use FriendsOfTYPO3\Headless\Middleware\SiteBaseRedirectResolver;
use FriendsOfTYPO3\Headless\Utility\Headless;
use FriendsOfTYPO3\Headless\Utility\HeadlessMode;
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -67,7 +69,7 @@ public function testJsonRedirect()

GeneralUtility::setContainer($container);

$resolver = new SiteBaseRedirectResolver();
$resolver = new SiteBaseRedirectResolver(new HeadlessMode());

$request = new ServerRequest();
$request = $request->withAttribute('site', $site);
Expand All @@ -76,6 +78,7 @@ public function testJsonRedirect()

$request = $request->withUri($uri);
$request = $request->withAttribute('routing', new SiteRouteResult($uri, $site));
$request = $request->withAttribute('headless', new Headless(HeadlessMode::FULL));

$response = $resolver->process($request, $this->prophesize(RequestHandler::class)->reveal());

Expand Down

0 comments on commit 23f3057

Please sign in to comment.