function SystemTestController::setHeader

Same name in other branches
  1. 9 core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php \Drupal\system_test\Controller\SystemTestController::setHeader()
  2. 10 core/modules/system/tests/modules/system_test/src/Controller/SystemTestController.php \Drupal\system_test\Controller\SystemTestController::setHeader()
  3. 11.x 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\Controller

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.