function AcceptHeaderMiddleware::handle
Same name in other branches
- 9 core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderMiddleware.php \Drupal\accept_header_routing_test\AcceptHeaderMiddleware::handle()
- 10 core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderMiddleware.php \Drupal\accept_header_routing_test\AcceptHeaderMiddleware::handle()
- 11.x core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderMiddleware.php \Drupal\accept_header_routing_test\AcceptHeaderMiddleware::handle()
File
-
core/
modules/ system/ tests/ modules/ accept_header_routing_test/ src/ AcceptHeaderMiddleware.php, line 26
Class
- AcceptHeaderMiddleware
- Example implementation of "accept header"-based content negotiation.
Namespace
Drupal\accept_header_routing_testCode
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
$mapping = [
'application/json' => 'json',
'application/hal+json' => 'hal_json',
'application/xml' => 'xml',
'text/html' => 'html',
];
$accept = $request->headers
->get('Accept') ?: [
'text/html',
];
if (isset($mapping[$accept[0]])) {
$request->setRequestFormat($mapping[$accept[0]]);
}
return $this->app
->handle($request, $type, $catch);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.