You are here

public function PageCacheAcceptHeaderController::content in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/system_test/src/Controller/PageCacheAcceptHeaderController.php \Drupal\system_test\Controller\PageCacheAcceptHeaderController::content()

Processes a request that will vary with Accept header.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request object.

Return value

mixed

1 string reference to 'PageCacheAcceptHeaderController::content'
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/PageCacheAcceptHeaderController.php, line 22

Class

PageCacheAcceptHeaderController
Defines a controller to respond the page cache accept header test.

Namespace

Drupal\system_test\Controller

Code

public function content(Request $request) {
  if ($request
    ->getRequestFormat() === 'json') {
    return new CacheableJsonResponse([
      'content' => 'oh hai this is json',
    ]);
  }
  else {
    return new CacheableResponse("<p>oh hai this is html.</p>");
  }
}