You are here

public function BanMiddleware::handle in Drupal 9

Same name and namespace in other branches
  1. 8 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) {
  $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);
}