Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BanMiddleware.php

function BanMiddleware::handle

Overrides HttpKernelInterface::handle

File

core/modules/ban/src/BanMiddleware.php, line 45

Class

BanMiddleware
Provides a HTTP middleware to implement IP based banning.

Namespace

Drupal\ban

Code

public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE) : Response {
    $ip = $request->getClientIp();
    if ($this->banIpManager
        ->isBanned($ip)) {
        return new Response(new FormattableMarkup('@ip has been banned', [
            '@ip' => $ip,
        ]), 403);
    }
    return $this->httpKernel
        ->handle($request, $type, $catch);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal