You are here

public function NegotiationMiddleware::handle in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php \Drupal\Core\StackMiddleware\NegotiationMiddleware::handle()

File

core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php, line 40

Class

NegotiationMiddleware
Provides a middleware to determine the content type upon the accept header.

Namespace

Drupal\Core\StackMiddleware

Code

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {

  // Register available mime types.
  foreach ($this->formats as $format => $mime_type) {
    $request
      ->setFormat($format, $mime_type);
  }

  // Determine the request format using the negotiator.
  if ($requested_format = $this
    ->getContentType($request)) {
    $request
      ->setRequestFormat($requested_format);
  }
  return $this->app
    ->handle($request, $type, $catch);
}