litespeedtech / lscache-drupal

LSCache Plugin for Drupal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined constant MAIN_REQUEST

rebelmusic opened this issue · comments

After upgrading Litespeed from 1.2 to 1.3, I am getting WSOD. Upon checking the logs, I see this:

php Error: Undefined constant Drupal\lite_speed_cache\StackMiddleware\LiteSpeedCache::MAIN_REQUEST in
                                            Drupal\lite_speed_cache\StackMiddleware\LiteSpeedCache->handle() (line 109 of...

I can see from this latest commit that MAIN_REQUEST is being used instead of MASTER_REQUEST.

MASTER_REQUEST is required for HttpKernelInterface:

interface HttpKernelInterface
{
    public const MASTER_REQUEST = 1;
    public const SUB_REQUEST = 2;

    /**
     * Handles a Request to convert it to a Response.
     *
     * When $catch is true, the implementation must catch all exceptions
     * and do its best to convert them to a Response instance.
     *
     * @param int  $type  The type of the request
     *                    (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
     * @param bool $catch Whether to catch exceptions or not
     *
     * @return Response A Response instance
     *
     * @throws \Exception When an Exception occurs during processing
     */
    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
}

Would be great if this can be fixed asap as I cannot use Litespeed anymore. I'll need to revert to 1.2 for now.

commented

As far as I know that MASTER_REQUEST is deprecated. I tried a fresh Drupal setup with the cache plugin and it seems no issue. Do you have any test site to uninstall the cache plugin, and install the latest version for testing porpuses and see if there's any issue?

I've installed v1.3 onto a newly setup Drupal 9 and encountered the same issue.

[10-Aug-2023 03:51:14 UTC] Error: Undefined constant Drupal\lite_speed_cache\StackMiddleware\LiteSpeedCache::MAIN_REQUEST in /home/foobar/web/modules/contrib/lscache-drupal/src/StackMiddleware/LiteSpeedCache.php on line 109 #0 /home/foobar/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\lite_speed_cache\StackMiddleware\LiteSpeedCache->handle()
#1 /home/foobar/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#2 /home/foobar/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#3 /home/foobar/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#4 /home/foobar/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#5 /home/foobar/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle()
#6 /home/foobar/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#7 {main}

Line 109 of LiteSpeedCache.php is this line:

if ($type === static::MAIN_REQUEST && $this->requestPolicy->check($request) === RequestPolicyInterface::ALLOW) {

the const LiteSpeedCache::MAIN_REQUEST is supposedly inherited from Symfony's HttpKernelInterface, but the attribute was only renamed from MASTER_REQUEST to MAIN_REQUEST since version 5.3:

Drupal 9.5.10 has a dependency on "symfony/http-kernel": "^4.4". Which means the HttpKernelInterface in Drupal 9 is still using the old MASTER_REQUEST reference. Not MAIN_REQUEST. So the current v1.3 lscache-drupal only works with Drupal 10 with Symfony 5.3+.

For backward compatibility purpose, I think the class Drupal\lite_speed_cache\StackMiddleware\LiteSpeedCache should explicitly declare public const MAIN_REQUEST = 1; within it.

Seems this has been taken care of in 310e4bd.

Please create a new release with that as soon as possible. Thanks.