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

Breadcrumb

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

function NegotiationMiddleware::handle

Overrides HttpKernelInterface::handle

File

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

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::MAIN_REQUEST, $catch = TRUE) : Response {
    // 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);
}
RSS feed
Powered by Drupal