public function SystemTestController::setHeader in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php \Drupal\system_test\Controller\SystemTestController::setHeader()
Sets a header.
1 string reference to 'SystemTestController::setHeader'
- system_test.routing.yml in core/
modules/ system/ tests/ modules/ system_test/ system_test.routing.yml - core/modules/system/tests/modules/system_test/system_test.routing.yml
File
- core/
modules/ system/ tests/ modules/ system_test/ src/ Controller/ SystemTestController.php, line 273
Class
- SystemTestController
- Controller routines for system_test routes.
Namespace
Drupal\system_test\ControllerCode
public function setHeader(Request $request) {
$query = $request->query
->all();
$response = new CacheableResponse();
$response->headers
->set($query['name'], $query['value']);
$response
->getCacheableMetadata()
->addCacheContexts([
'url.query_args:name',
'url.query_args:value',
]);
$response
->setContent($this
->t('The following header was set: %name: %value', [
'%name' => $query['name'],
'%value' => $query['value'],
]));
return $response;
}