summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2013-12-30 11:38:30 -0500
committerDavid Rothstein <drothstein@gmail.com>2013-12-30 11:38:30 -0500
commit6cd1aae9884952d2eb9750133c85c1c52c3ba26f (patch)
treebcc0a742dc9453673f486c619afac53e8d2b4af3
parent001532a06e070f209c2e771720435a3e08c0cc8c (diff)
downloadbrdo-6cd1aae9884952d2eb9750133c85c1c52c3ba26f.tar.gz
brdo-6cd1aae9884952d2eb9750133c85c1c52c3ba26f.tar.bz2
Issue #1476810 by Spleshka, David_Rothstein, franz | Heine: Drupal_serve_page_from_cache can serve uncompressed data with Content-Encoding gzip header with page_cache_without_database = 1.
-rw-r--r--CHANGELOG.txt4
-rw-r--r--includes/bootstrap.inc2
-rw-r--r--includes/common.inc9
-rw-r--r--modules/simpletest/tests/bootstrap.test12
4 files changed, 25 insertions, 2 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 89c12caff..044b56dd1 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,10 @@
Drupal 7.25, xxxx-xx-xx (development version)
-----------------------
+- Fixed a bug which caused cached pages to sometimes be sent to the browser
+ with incorrect compression. The fix adds a new 'page_compressed' key to the
+ $cache->data array returned by drupal_page_get_cache() (minor data structure
+ change).
- Fixed broken tests on PHP 5.5.
- Made the File and Image modules more robust when saving entities that have
deleted files attached. The code in file_field_presave() will now remove the
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 7a4493991..5511d7c5d 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -1278,7 +1278,7 @@ function drupal_page_header() {
*/
function drupal_serve_page_from_cache(stdClass $cache) {
// Negotiate whether to use compression.
- $page_compression = variable_get('page_compression', TRUE) && extension_loaded('zlib');
+ $page_compression = !empty($cache->data['page_compressed']);
$return_compressed = $page_compression && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE;
// Get headers set in hook_boot(). Keys are lower-case.
diff --git a/includes/common.inc b/includes/common.inc
index 9cd73f4e2..38895c542 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -5176,6 +5176,10 @@ function drupal_page_set_cache() {
global $base_root;
if (drupal_page_is_cacheable()) {
+
+ // Check whether the current page might be compressed.
+ $page_compressed = variable_get('page_compression', TRUE) && extension_loaded('zlib');
+
$cache = (object) array(
'cid' => $base_root . request_uri(),
'data' => array(
@@ -5183,6 +5187,9 @@ function drupal_page_set_cache() {
'body' => ob_get_clean(),
'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,
),
'expire' => CACHE_TEMPORARY,
'created' => REQUEST_TIME,
@@ -5200,7 +5207,7 @@ function drupal_page_set_cache() {
}
if ($cache->data['body']) {
- if (variable_get('page_compression', TRUE) && extension_loaded('zlib')) {
+ if ($page_compressed) {
$cache->data['body'] = gzencode($cache->data['body'], 9, FORCE_GZIP);
}
cache_set($cache->cid, $cache->data, 'cache_page', $cache->expire);
diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test
index 87b59608e..4fda15c8c 100644
--- a/modules/simpletest/tests/bootstrap.test
+++ b/modules/simpletest/tests/bootstrap.test
@@ -219,6 +219,18 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase {
$this->assertFalse($this->drupalGetHeader('Content-Encoding'), 'A Content-Encoding header was not sent.');
$this->assertTitle(t('Welcome to @site-name | @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), 'Site title matches.');
$this->assertRaw('</html>', 'Page was not compressed.');
+
+ // Disable compression mode.
+ variable_set('page_compression', FALSE);
+
+ // 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).');
}
}