diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index ecf25f7..006871c 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -9,6 +9,8 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\State\StateInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Tests\Core\Cache\CacheTagsInvalidatorTest; @@ -262,17 +264,18 @@ public function execute() { $output = $this->view->render(); - /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */ - $cache = $this->getPlugin('cache'); - $header = []; $header['Content-type'] = $this->getMimeType(); - $header['X-Drupal-Cache-Tags'] = implode(' ', $cache->getCacheTags()); - $max_age = $cache->getCacheMaxAge(); - $header['Cache-Control'] = 'public, max-age=' . $max_age; + $response = new CacheableResponse($this->renderer->renderRoot($output), 200); - $response = new Response(drupal_render_root($output), 200, $header); + $cache_metadata = new CacheableMetadata(); + + /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */ + $cache = $this->getPlugin('cache'); + $cache_metadata->setCacheTags($cache->getCacheTags()); + $cache_metadata->setCacheMaxAge($cache->getCacheMaxAge()); + $response->addCacheableDependency($cache_metadata); return $response; }