How to add, replace or remove Middleware

This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
Oct 4, 2019
By hissy for Developers

HTTP middlewares are configured in concrete/config/app.php

    'middleware' => [
        [
            'priority' => 1,
            'class' => \Concrete\Core\Http\Middleware\ApplicationMiddleware::class,
        ],
        'core_cookie' => \Concrete\Core\Http\Middleware\CookieMiddleware::class,
        'core_xframeoptions' => \Concrete\Core\Http\Middleware\FrameOptionsMiddleware::class,
        'core_thumbnails' => '\Concrete\Core\Http\Middleware\ThumbnailMiddleware',
    ],

You can add your own middleware by overriding config value from application/config/app.php. Of course, you can change the class too.

return [
    'middleware' => [
        'core_cookie' => \Application\Concrete\Http\Middleware\MyCustomizedCookieMiddleware::class,
        'my_great_middleware' => \Application\Concrete\Http\Middleware\MyGreatMiddleware::class,
    ],
];

If you want to remove a core middleware, you need to create a passthru middleware.

return [
    'middleware' => [
        'core_xframeoptions' => \Application\Concrete\Http\Middleware\PassThruMiddleware::class,
    ],
];
<?php
namespace Application\Concrete\Http\Middleware;

use Concrete\Core\Http\Middleware\DelegateInterface;
use Concrete\Core\Http\Middleware\MiddlewareInterface;
use Symfony\Component\HttpFoundation\Request;

class PassThruMiddleware implements MiddlewareInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(Request $request, DelegateInterface $frame)
    {
        // PassThru
        return $frame->next($request);
    }
}
Recent Tutorials
Create custom Site Health tasks
Apr 19, 2024
By myq.

This tutorial will guide you through the creation of a new Site Health task

Reusing the same Express entity in multiple associations
Apr 11, 2024
By myq.

How to create and manage multiple associations in Express

Express Form Styling
Apr 11, 2024
By myq.

Different ways to style Express forms

Setting addon/theme version compatibility in the marketplace
Jan 9, 2024

For developers worn out with setting the latest addon or theme version manually across too many core versions, here is a JavaScript bookmarklet to do it for you.

How to get the locale of a page
Jan 8, 2024
By wtfdesign.

Now, why don't we just have a getLocale() method on Page objects beats me, but here's how you work around it

Using a Redis Server
Jun 16, 2023
By mlocati.

How to configure Concrete to use one or more Redis servers to persist the cache.

Improvements?

Let us know by posting here.