Commit 3bc5a5cd authored by alexpott's avatar alexpott

Issue #2467041 by mr.baileys, jan.stoeckler: max-age on HTML responses wrongly...

Issue #2467041 by mr.baileys, jan.stoeckler: max-age on HTML responses wrongly set to `max-age=0, private` instead of `max-age=N, public` (breaks reverse proxies and client-side caching)
parent 54ba27d8
......@@ -157,12 +157,10 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
// entire render cache, regardless of the cache bin.
$cache_contexts = [];
$cache_tags = ['rendered'];
$cache_max_age = Cache::PERMANENT;
foreach (['page_top', 'page', 'page_bottom'] as $region) {
if (isset($html[$region])) {
$cache_contexts = Cache::mergeContexts($cache_contexts, $html[$region]['#cache']['contexts']);
$cache_tags = Cache::mergeTags($cache_tags, $html[$region]['#cache']['tags']);
$cache_max_age = Cache::mergeMaxAges($cache_max_age, $html[$region]['#cache']['max-age']);
}
}
......@@ -174,11 +172,6 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
'X-Drupal-Cache-Contexts' => implode(' ', $this->cacheContexts->optimizeTokens($cache_contexts)),
'X-Generator' => 'Drupal ' . $version . ' (https://www.drupal.org)'
]);
// If an explicit non-infinite max-age is specified by a part of the page,
// respect that by applying it to the response's headers.
if ($cache_max_age !== Cache::PERMANENT) {
$response->setMaxAge($cache_max_age);
}
return $response;
}
......
......@@ -236,6 +236,12 @@ function testPageCache() {
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent.');
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.');
// Until bubbling of max-age up to the response is supported, verify that
// a custom #cache max-age set on an element does not affect page max-age.
$this->drupalLogout();
$this->drupalGet('system-test/cache_maxage_page');
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=300, public');
}
/**
......
......@@ -204,6 +204,19 @@ public function system_test_cache_tags_page() {
return $build;
}
/**
* Set cache max-age on the returned render array.
*/
public function system_test_cache_maxage_page() {
$build['main'] = array(
'#cache' => array('max-age' => 90),
'message' => array(
'#markup' => 'Cache max-age page example',
),
);
return $build;
}
/**
* Sets a cache tag on an element to help test #pre_render and cache tags.
*/
......
......@@ -66,6 +66,13 @@ system_test.cache_tags_page:
requirements:
_access: 'TRUE'
system_test.cache_maxage_page:
path: '/system-test/cache_maxage_page'
defaults:
_controller: '\Drupal\system_test\Controller\SystemTestController::system_test_cache_maxage_page'
requirements:
_access: 'TRUE'
system_test.authorize_init:
path: '/system-test/authorize-init/{page_title}'
defaults:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment