Issue #1476810 by Spleshka, franz: Fixed drupal_serve_page_from_cache() can serve uncompressed data with Content-Encoding gzip header with page_cache_without_database = 1.
parent
7827f1d7dd
commit
21d59b5009
|
@ -1225,7 +1225,7 @@ function drupal_serve_page_from_cache(stdClass $cache, Response $response, Reque
|
|||
// First half: we must determine if we should be returning a 304.
|
||||
|
||||
// Negotiate whether to use compression.
|
||||
$page_compression = $config->get('response.gzip') && extension_loaded('zlib');
|
||||
$page_compression = !empty($cache->data['page_compressed']) && extension_loaded('zlib');
|
||||
$return_compressed = $page_compression && $request->server->has('HTTP_ACCEPT_ENCODING') && strpos($request->server->get('HTTP_ACCEPT_ENCODING'), 'gzip') !== FALSE;
|
||||
|
||||
// Get headers. Keys are lower-case.
|
||||
|
|
|
@ -3171,6 +3171,10 @@ function _drupal_bootstrap_full($skip = FALSE) {
|
|||
*/
|
||||
function drupal_page_set_cache(Response $response, Request $request) {
|
||||
if (drupal_page_is_cacheable()) {
|
||||
|
||||
// Check if the current page may be compressed.
|
||||
$page_compressed = config('system.performance')->get('response.gzip') && extension_loaded('zlib');
|
||||
|
||||
$cache = (object) array(
|
||||
'cid' => drupal_page_cache_get_cid($request),
|
||||
'data' => array(
|
||||
|
@ -3178,6 +3182,9 @@ function drupal_page_set_cache(Response $response, Request $request) {
|
|||
'body' => $response->getContent(),
|
||||
'title' => drupal_get_title(),
|
||||
'headers' => array(),
|
||||
// We need to store whether page was compressed or not,
|
||||
// because by the time it is read, the configuration might change.
|
||||
'page_compressed' => $page_compressed,
|
||||
),
|
||||
'tags' => array('content' => TRUE),
|
||||
'expire' => CacheBackendInterface::CACHE_PERMANENT,
|
||||
|
@ -3199,7 +3206,7 @@ function drupal_page_set_cache(Response $response, Request $request) {
|
|||
}
|
||||
|
||||
if ($cache->data['body']) {
|
||||
if (config('system.performance')->get('response.gzip') && extension_loaded('zlib')) {
|
||||
if ($page_compressed) {
|
||||
$cache->data['body'] = gzencode($cache->data['body'], 9, FORCE_GZIP);
|
||||
}
|
||||
cache('page')->set($cache->cid, $cache->data, $cache->expire, $cache->tags);
|
||||
|
|
|
@ -202,5 +202,18 @@ class PageCacheTest extends WebTestBase {
|
|||
$this->assertFalse($this->drupalGetHeader('Content-Encoding'), 'A Content-Encoding header was not sent.');
|
||||
$this->assertTitle(t('Test page | @site-name', array('@site-name' => config('system.site')->get('name'))), 'Site title matches.');
|
||||
$this->assertRaw('</html>', 'Page was not compressed.');
|
||||
|
||||
// Disable compression mode.
|
||||
$config->set('response.gzip', 0);
|
||||
$config->save();
|
||||
|
||||
// Verify if cached page is still available for a client with compression support.
|
||||
$this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate'));
|
||||
$this->drupalSetContent(gzinflate(substr($this->drupalGetContent(), 10, -8)));
|
||||
$this->assertRaw('</html>', 'Page was delivered after compression mode is changed (compression support enabled).');
|
||||
|
||||
// Verify if cached page is still available for a client without compression support.
|
||||
$this->drupalGet('');
|
||||
$this->assertRaw('</html>', 'Page was delivered after compression mode is changed (compression support disabled).');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue