function BanMiddleware::handle

Same name in other branches
  1. 8.9.x core/modules/ban/src/BanMiddleware.php \Drupal\ban\BanMiddleware::handle()
  2. 10 core/modules/ban/src/BanMiddleware.php \Drupal\ban\BanMiddleware::handle()
  3. 11.x core/modules/ban/src/BanMiddleware.php \Drupal\ban\BanMiddleware::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::MASTER_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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.