diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/aggregator/aggregator.pages.inc | 4 | ||||
-rw-r--r-- | modules/aggregator/tests/aggregator_test.module | 12 | ||||
-rw-r--r-- | modules/blogapi/blogapi.module | 2 | ||||
-rw-r--r-- | modules/node/node.module | 2 | ||||
-rw-r--r-- | modules/simpletest/tests/bootstrap.test | 55 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 10 | ||||
-rw-r--r-- | modules/simpletest/tests/file.test | 2 | ||||
-rw-r--r-- | modules/simpletest/tests/session.test | 8 | ||||
-rw-r--r-- | modules/simpletest/tests/system_test.module | 10 | ||||
-rw-r--r-- | modules/system/system.module | 2 |
10 files changed, 80 insertions, 27 deletions
diff --git a/modules/aggregator/aggregator.pages.inc b/modules/aggregator/aggregator.pages.inc index c311dab14..79d80d041 100644 --- a/modules/aggregator/aggregator.pages.inc +++ b/modules/aggregator/aggregator.pages.inc @@ -371,7 +371,7 @@ function aggregator_page_rss() { * @ingroup themeable */ function theme_aggregator_page_rss($feeds, $category = NULL) { - drupal_set_header('Content-Type: application/rss+xml; charset=utf-8'); + drupal_set_header('Content-Type', 'application/rss+xml; charset=utf-8'); $items = ''; $feed_length = variable_get('feed_item_length', 'teaser'); @@ -431,7 +431,7 @@ function aggregator_page_opml($cid = NULL) { * @ingroup themeable */ function theme_aggregator_page_opml($feeds) { - drupal_set_header('Content-Type: text/xml; charset=utf-8'); + drupal_set_header('Content-Type', 'text/xml; charset=utf-8'); $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $output .= "<opml version=\"1.1\">\n"; diff --git a/modules/aggregator/tests/aggregator_test.module b/modules/aggregator/tests/aggregator_test.module index 4c17d73f6..61b64652a 100644 --- a/modules/aggregator/tests/aggregator_test.module +++ b/modules/aggregator/tests/aggregator_test.module @@ -33,21 +33,21 @@ function aggregator_test_feed($use_last_modified = FALSE, $use_etag = FALSE) { // Send appropriate response. We respond with a 304 not modified on either // etag or on last modified. if ($use_last_modified) { - drupal_set_header("Last-Modified: " . gmdate(DATE_RFC1123, $last_modified)); + drupal_set_header('Last-Modified', gmdate(DATE_RFC1123, $last_modified)); } if ($use_etag) { - drupal_set_header("ETag: " .$etag); + drupal_set_header('ETag', $etag); } // Return 304 not modified if either last modified or etag match. if ($last_modified == $if_modified_since || $etag == $if_none_match) { - drupal_set_header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified'); + drupal_set_header('304 Not Modified'); return; } // The following headers force validation of cache: - drupal_set_header("Expires: Sun, 19 Nov 1978 05:00:00 GMT"); - drupal_set_header("Cache-Control: must-revalidate"); - drupal_set_header('Content-Type: application/rss+xml; charset=utf-8'); + drupal_set_header('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT'); + drupal_set_header('Cache-Control', 'must-revalidate'); + drupal_set_header('Content-Type', 'application/rss+xml; charset=utf-8'); // Read actual feed from file. $file_name = DRUPAL_ROOT . '/' . drupal_get_path('module', 'aggregator') . '/tests/aggregator_test_rss091.xml'; diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module index 480dcabf0..575a07b74 100644 --- a/modules/blogapi/blogapi.module +++ b/modules/blogapi/blogapi.module @@ -849,7 +849,7 @@ function blogapi_rsd() { $base = url('', array('absolute' => TRUE)); $blogid = 1; # until we figure out how to handle multiple bloggers - drupal_set_header('Content-Type: application/rsd+xml; charset=utf-8'); + drupal_set_header('Content-Type', 'application/rsd+xml; charset=utf-8'); print <<<__RSD__ <?xml version="1.0"?> <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> diff --git a/modules/node/node.module b/modules/node/node.module index 4e19ecebc..df85fbeaf 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1998,7 +1998,7 @@ function node_feed($nids = FALSE, $channel = array()) { $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']); $output .= "</rss>\n"; - drupal_set_header('Content-Type: application/rss+xml; charset=utf-8'); + drupal_set_header('Content-Type', 'application/rss+xml; charset=utf-8'); print $output; } diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test index eedf1a914..f999f7e6f 100644 --- a/modules/simpletest/tests/bootstrap.test +++ b/modules/simpletest/tests/bootstrap.test @@ -96,18 +96,22 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase { ); } + function setUp() { + parent::setUp('system_test'); + } + /** - * Enable cache and examine HTTP headers. + * Test support for requests containing If-Modified-Since and If-None-Match headers. */ - function testPageCache() { + function testConditionalRequests() { variable_set('cache', CACHE_NORMAL); // Fill the cache. $this->drupalGet(''); $this->drupalHead(''); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); $etag = $this->drupalGetHeader('ETag'); - $this->assertTrue($etag, t('An ETag header was sent, indicating that page was cached.')); $last_modified = $this->drupalGetHeader('Last-Modified'); $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag)); @@ -121,19 +125,58 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase { $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified)); $this->assertResponse(200, t('Conditional request without If-None-Match returned 200 OK.')); - $this->assertTrue($this->drupalGetHeader('ETag'), t('An ETag header was sent, indicating that page was cached.')); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC1123, strtotime($last_modified) + 1), 'If-None-Match: ' . $etag)); $this->assertResponse(200, t('Conditional request with new a If-Modified-Since date newer than Last-Modified returned 200 OK.')); - $this->assertTrue($this->drupalGetHeader('ETag'), t('An ETag header was sent, indicating that page was cached.')); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); $user = $this->drupalCreateUser(); $this->drupalLogin($user); $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag)); $this->assertResponse(200, t('Conditional request returned 200 OK for authenticated user.')); - $this->assertFalse($this->drupalGetHeader('ETag'), t('An ETag header was not sent, indicating that page was not cached.')); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Absense of Page was not cached.')); } + /** + * Test cache headers. + */ + function testPageCache() { + variable_set('cache', CACHE_NORMAL); + + // Fill the cache. + $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Page was not cached.')); + $this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', t('Vary header was sent.')); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', t('Cache-Control header was sent.')); + $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.')); + $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.')); + + // Check cache. + $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); + $this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', t('Vary: Cookie header was sent.')); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', t('Cache-Control header was sent.')); + $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.')); + $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.')); + + // Check replacing default headers. + $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Expires', 'value' => 'Fri, 19 Nov 2008 05:00:00 GMT'))); + $this->assertEqual($this->drupalGetHeader('Expires'), 'Fri, 19 Nov 2008 05:00:00 GMT', t('Default header was replaced.')); + $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Vary', 'value' => 'User-Agent'))); + $this->assertEqual($this->drupalGetHeader('Vary'), 'User-Agent,Accept-Encoding', t('Default header was replaced.')); + + // Check that authenticated users bypass the cache. + $user = $this->drupalCreateUser(); + $this->drupalLogin($user); + $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Caching was bypassed.')); + $this->assertFalse($this->drupalGetHeader('Vary'), t('Vary header was not sent.')); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', t('Cache-Control header was sent.')); + $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.')); + $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.')); + + } } class BootstrapVariableTestCase extends DrupalWebTestCase { diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 2a2af52f7..58b37cfc8 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -647,21 +647,21 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase { '%type' => 'Notice', '%message' => 'Undefined variable: bananas', '%function' => 'system_test_generate_warnings()', - '%line' => 184, + '%line' => 194, '%file' => realpath('modules/simpletest/tests/system_test.module'), ); $error_warning = array( '%type' => 'Warning', '%message' => 'Division by zero', '%function' => 'system_test_generate_warnings()', - '%line' => 186, + '%line' => 196, '%file' => realpath('modules/simpletest/tests/system_test.module'), ); $error_user_notice = array( '%type' => 'User notice', '%message' => 'Drupal is awesome', '%function' => 'system_test_generate_warnings()', - '%line' => 188, + '%line' => 198, '%file' => realpath('modules/simpletest/tests/system_test.module'), ); @@ -695,14 +695,14 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase { '%type' => 'Exception', '%message' => 'Drupal is awesome', '%function' => 'system_test_trigger_exception()', - '%line' => 197, + '%line' => 207, '%file' => realpath('modules/simpletest/tests/system_test.module'), ); $error_pdo_exception = array( '%type' => 'PDOException', '%message' => 'SQLSTATE', '%function' => 'system_test_trigger_pdo_exception()', - '%line' => 205, + '%line' => 215, '%file' => realpath('modules/simpletest/tests/system_test.module'), ); diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test index 21ef6d482..7afc6f5c8 100644 --- a/modules/simpletest/tests/file.test +++ b/modules/simpletest/tests/file.test @@ -1919,7 +1919,7 @@ class FileDownloadTest extends FileTestCase { $url = file_create_url($file->filename); // Set file_test access header to allow the download. - file_test_set_return('download', array('x-foo: Bar')); + file_test_set_return('download', array('x-foo' => 'Bar')); $this->drupalHead($url); $headers = $this->drupalGetHeaders(); $this->assertEqual($headers['x-foo'] , 'Bar', t('Found header set by file_test module on private download.')); diff --git a/modules/simpletest/tests/session.test b/modules/simpletest/tests/session.test index 1ee80485e..d713cbb38 100644 --- a/modules/simpletest/tests/session.test +++ b/modules/simpletest/tests/session.test @@ -163,7 +163,7 @@ class SessionTestCase extends DrupalWebTestCase { $this->assertSessionCookie(TRUE); $this->assertSessionStarted(TRUE); $this->assertSessionEmpty(TRUE); - $this->assertFalse($this->drupalGetHeader('ETag'), t('Page was not cached.')); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Page was not cached.')); // When PHP deletes a cookie, it sends "Set-Cookie: cookiename=deleted; // expires=..." $this->assertTrue(preg_match('/SESS\w+=deleted/', $this->drupalGetHeader('Set-Cookie')), t('Session cookie was deleted.')); @@ -185,7 +185,7 @@ class SessionTestCase extends DrupalWebTestCase { $this->assertSessionCookie(TRUE); $this->assertSessionStarted(TRUE); $this->assertSessionEmpty(FALSE); - $this->assertFalse($this->drupalGetHeader('ETag'), t('Page was not cached.')); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Caching was bypassed.')); $this->assertText(t('This is a dummy message.'), t('Message was displayed.')); // During this request the session is destroyed in _drupal_bootstrap(), @@ -194,7 +194,7 @@ class SessionTestCase extends DrupalWebTestCase { $this->assertSessionCookie(TRUE); $this->assertSessionStarted(TRUE); $this->assertSessionEmpty(TRUE); - $this->assertTrue($this->drupalGetHeader('ETag'), t('Page was cached.')); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); $this->assertNoText(t('This is a dummy message.'), t('Message was not cached.')); $this->assertTrue(preg_match('/SESS\w+=deleted/', $this->drupalGetHeader('Set-Cookie')), t('Session cookie was deleted.')); @@ -202,7 +202,7 @@ class SessionTestCase extends DrupalWebTestCase { $this->drupalGet(''); $this->assertSessionCookie(FALSE); $this->assertSessionStarted(FALSE); - $this->assertTrue($this->drupalGetHeader('ETag'), t('Page was cached.')); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); $this->assertFalse($this->drupalGetHeader('Set-Cookie'), t('New session was not started.')); // Verify that modifying $_SESSION without having started a session diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module index df13b2440..68b6e5cb7 100644 --- a/modules/simpletest/tests/system_test.module +++ b/modules/simpletest/tests/system_test.module @@ -17,6 +17,11 @@ function system_test_menu() { 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); + $items['system-test/set-header'] = array( + 'page callback' => 'system_test_set_header', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); $items['system-test/redirect-noscheme'] = array( 'page callback' => 'system_test_redirect_noscheme', 'access arguments' => array('access content'), @@ -95,6 +100,11 @@ function system_test_redirect($code) { return ''; } +function system_test_set_header() { + drupal_set_header($_GET['name'], $_GET['value']); + return t('The following header was set: %name: %value', array('%name' => $_GET['name'], '%value' => $_GET['value'])); +} + function system_test_redirect_noscheme() { header("Location: localhost/path", TRUE, 301); exit; diff --git a/modules/system/system.module b/modules/system/system.module index e0ac65c9f..1c1c33e43 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -2289,7 +2289,7 @@ function theme_meta_generator_html($version = VERSION) { * @ingroup themeable */ function theme_meta_generator_header($version = VERSION) { - drupal_set_header('X-Generator: Drupal ' . $version . ' (http://drupal.org)'); + drupal_set_header('X-Generator', 'Drupal ' . $version . ' (http://drupal.org)'); } /** |