Create and Install a Custom Module Create an Event Subscriber in the Custom Module . Place the Event Subscriber file in the src/EventSubscriber folder of the custom module. <?php // In your_module/src/EventSubscriber/CustomHeaderSubscriber.php namespace Drupal\custom\EventSubscriber ; use Symfony\Component\EventDispatcher\ EventSubscriberInterface ; use Symfony\Component\HttpKernel\Event\ RequestEvent ; use Symfony\Component\HttpKernel\ KernelEvents ; use Symfony\Component\HttpKernel\Exception\ AccessDeniedHttpException ; use Symfony\Component\HttpFoundation\ Response ; /** * Event subscriber to check for a custom header in incoming requests. */ class CustomHeaderSubscriber implements EventSubscriberInterface { /** * { @inheritdoc } */ public static function getSubscribedEvents () { // Subscribe to the request event, with a priority of 30 $ events [ KernelEvents:: REQUEST ][] = [ 'checkCusto...