summaryrefslogtreecommitdiffstats
path: root/core/modules/system/tests/modules/system_test/src/Controller/PageCacheAcceptHeaderController.php
blob: c24d7c51429b4970a3f804a0a745c12158cce090 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

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

namespace Drupal\system_test\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

/**
 * 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) {
    if ($request->getRequestFormat() === 'json') {
      return new JsonResponse(array('content' => 'oh hai this is json'));
    }
    else {
      return new Response("<p>oh hai this is html.</p>");
    }
  }
}