PageCacheAcceptHeaderController.php 866 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\system_test\Controller\PageCacheAcceptHeaderController.
 */

namespace Drupal\system_test\Controller;

10 11
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableResponse;
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use Symfony\Component\HttpFoundation\Request;

/**
 * Defines a controller to respond the page cache accept header test.
 */
class PageCacheAcceptHeaderController {

  /**
   * Processes a request that will vary with Accept header.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request object.
   *
   * @return mixed
   */
  public function content(Request $request) {
28
    if ($request->getRequestFormat() === 'json') {
29
      return new CacheableJsonResponse(['content' => 'oh hai this is json']);
30 31
    }
    else {
32
      return new CacheableResponse("<p>oh hai this is html.</p>");
33 34 35 36
    }
  }
}