Commit fb3b6d13 authored by Dries's avatar Dries

- Patch #231190 by eli, mfb: page cache didn't work with HEAD requests.

parent 57fe5103
......@@ -17,7 +17,7 @@ Drupal 7.0, xxxx-xx-xx (development version)
order can now be customised using the Views module.
* Added more features to the default install profile, and a new
slimmed down install profile for developers.
* Image toolkits are added by modules instead of being copied to
* Image toolkits are added by modules instead of being copied to
the includes directory.
- Search:
* Added support for language-aware searches.
......
......@@ -549,7 +549,7 @@ function page_get_cache() {
$cache = NULL;
if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' && count(drupal_set_message()) == 0) {
if (!$user->uid && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') && count(drupal_set_message()) == 0) {
$cache = cache_get($base_root . request_uri(), 'cache_page');
if (empty($cache)) {
......
......@@ -2490,7 +2490,7 @@ function _drupal_bootstrap_full() {
function page_set_cache() {
global $user, $base_root;
if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' && count(drupal_get_messages(NULL, FALSE)) == 0) {
if (!$user->uid && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') && count(drupal_get_messages(NULL, FALSE)) == 0) {
// This will fail in some cases, see page_get_cache() for the explanation.
if ($data = ob_get_contents()) {
$cache = TRUE;
......
......@@ -81,3 +81,29 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
);
}
}
class BootstrapPageCacheTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
function getInfo() {
return array(
'name' => t('Page cache test'),
'description' => t('Enable the page cache, submit a HEAD request and examine headers.'),
'group' => t('Bootstrap')
);
}
/**
* Enable cache and examine HTTP headers.
*/
function testPageCache() {
global $base_url;
variable_set('cache', 1);
// Retrieve the front page, which has already been cached by $this->curlConnect();
$this->drupalHead($base_url);
$this->assertText('ETag: ', t('Verify presence of ETag header indicating that page caching is enabled.'));
}
}
......@@ -478,8 +478,8 @@ function _block_render_blocks($region_blocks) {
if ($block->enabled && $block->page_match) {
// Try fetching the block from cache. Block caching is not compatible with
// node_access modules. We also preserve the submission of forms in blocks,
// by fetching from cache only if the request method is 'GET'.
if (!count(module_implements('node_grants')) && $_SERVER['REQUEST_METHOD'] == 'GET' && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) {
// by fetching from cache only if the request method is 'GET' (or 'HEAD').
if (!count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) {
$array = $cache->data;
}
else {
......
......@@ -759,7 +759,7 @@ protected function curlExec($curl_options) {
$this->_content = curl_exec($this->ch);
$this->plain_text = FALSE;
$this->elements = FALSE;
$this->assertTrue($this->_content !== FALSE, t('!method to !url, response is !length bytes.', array('!method' => empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST', '!url' => $url, '!length' => strlen($this->_content))), t('Browser'));
$this->assertTrue($this->_content !== FALSE, t('!method to !url, response is !length bytes.', array('!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'), '!url' => $url, '!length' => strlen($this->_content))), t('Browser'));
return $this->_content;
}
......@@ -802,7 +802,7 @@ protected function parse() {
* Retrieves a Drupal path or an absolute path.
*
* @param $path
* Drupal path or url to load into internal browser
* Drupal path or URL to load into internal browser
* @param $options
* Options to be forwarded to url().
* @return
......@@ -814,7 +814,7 @@ function drupalGet($path, $options = array()) {
// We re-using a CURL connection here. If that connection still has certain
// options set, it might change the GET into a POST. Make sure we clear out
// previous options.
$out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => url($path, $options)));
$out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => url($path, $options), CURLOPT_HEADER => FALSE, CURLOPT_NOBODY => FALSE));
$this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up.
return $out;
}
......@@ -874,7 +874,7 @@ function drupalPost($path, $edit, $submit, $options = array()) {
}
$post = implode('&', $post);
}
$out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post));
$out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HEADER => FALSE, CURLOPT_NOBODY => FALSE));
// Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
return $out;
......@@ -889,6 +889,40 @@ function drupalPost($path, $edit, $submit, $options = array()) {
}
}
/**
* Retrieves only the headers for a Drupal path or an absolute path.
*
* @param $path
* Drupal path or URL to load into internal browser
* @param $options
* Options to be forwarded to url().
* @return
* The retrieved headers, also available as $this->drupalGetContent()
*/
function drupalHead($path, $options = array()) {
$options['absolute'] = TRUE;
$out = $this->curlExec(array(CURLOPT_HEADER => TRUE, CURLOPT_NOBODY => TRUE, CURLOPT_URL => url($path, $options)));
$this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up.
return $out;
}
/**
* Retrieves only the headers for a Drupal path or an absolute path.
*
* @param $path
* Drupal path or url to load into internal browser
* @param $options
* Options to be forwarded to url().
* @return
* The retrieved headers, also available as $this->drupalGetContent()
*/
function drupalHead($path, $options = array()) {
$options['absolute'] = TRUE;
$out = $this->curlExec(array(CURLOPT_HEADER => TRUE, CURLOPT_NOBODY => TRUE, CURLOPT_URL => url($path, $options)));
$this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up.
return $out;
}
/**
* Handle form input related to drupalPost(). Ensure that the specified fields
* exist and attempt to create POST data in the correct manner for the particular
......
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