Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.59
diff -u -p -r1.59 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	24 Nov 2008 04:22:02 -0000	1.59
+++ modules/simpletest/drupal_web_test_case.php	24 Nov 2008 18:14:42 -0000
@@ -6,6 +6,7 @@
  */
 class DrupalWebTestCase {
   protected $_logged_in = FALSE;
+  protected $_headers;
   protected $_content;
   protected $_url;
   protected $plain_text;
@@ -828,6 +829,7 @@ class DrupalWebTestCase {
     $this->curlInitialize();
     $url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL];
     curl_setopt_array($this->ch, $this->curl_options + $curl_options);
+    $this->_headers = array();
     $this->drupalSetContent(curl_exec($this->ch), curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL));
     $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->drupalGetContent();
@@ -842,6 +844,7 @@ class DrupalWebTestCase {
    * @param $header a header.
    */
   protected function curlHeaderCallback($ch, $header) {
+    $this->_headers[] = $header;
     // Errors are being sent via X-Drupal-Assertion-* headers,
     // generated by _drupal_log_error() in the exact form required
     // by DrupalWebTestCase::error().
@@ -904,7 +907,7 @@ class DrupalWebTestCase {
     // 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), CURLOPT_HEADER => FALSE, CURLOPT_NOBODY => FALSE));
+    $out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => url($path, $options), CURLOPT_NOBODY => FALSE));
     $this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up.
 
     // Replace original page output with new output from redirected page(s).
@@ -986,7 +989,7 @@ class DrupalWebTestCase {
             }
             $post = implode('&', $post);
           }
-          $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HEADER => FALSE));
+          $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post));
           // Ensure that any changes to variables in the other thread are picked up.
           $this->refreshVariables();
 
@@ -1040,7 +1043,7 @@ class DrupalWebTestCase {
    */
   function drupalHead($path, $options = array()) {
     $options['absolute'] = TRUE;
-    $out = $this->curlExec(array(CURLOPT_HEADER => TRUE, CURLOPT_NOBODY => TRUE, CURLOPT_URL => url($path, $options)));
+    $out = $this->curlExec(array(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;
   }
@@ -1324,6 +1327,65 @@ class DrupalWebTestCase {
   }
 
   /**
+   * Gets the HTTP response headers of the requested page. Normally we are only
+   * interested in the headers returned by the last request. However, if a page
+   * is redirected or HTTP authentication is in use, multiple requests will be
+   * required to retrieve the page. Headers from all requests may be requested
+   * by passing TRUE to this function.
+   *
+   * @param $all_requests
+   *   Boolean value specifying whether to return headers from all requests
+   *   instead of just the last request. Defaults to FALSE.
+   * @return
+   *   A name/value array if headers from only the last request are requested.
+   *   If headers from all requests are requested, an array of name/value
+   *   arrays, one for each request.
+   *
+   *   The pseudonym ":status" is used for the HTTP status line.
+   */
+  function drupalGetHeaders($all_requests = FALSE) {
+    $request = 0;
+    $headers = array($request => array());
+    foreach ($this->_headers as $header) {
+      $header = trim($header);
+      if ($header === '') {
+        $request++;
+      }
+      else {
+        if (strpos($header, 'HTTP/') === 0) {
+          list($name, $value) = array(':status' => $header);
+        }
+        else {
+          list($name, $value) = explode(':', $header, 2);
+        }
+        if (isset($headers[$request][$name])) {
+          $headers[$request][$name] .= ',' . trim($value);
+        }
+        else {
+          $headers[$request][$name] = trim($value);
+        }
+      }
+    }
+    if (!$all_requests) {
+      $headers = array_pop($headers);
+    }
+    return $headers;
+  }
+
+  /**
+   * Gets the value of an HTTP response header returned by the last request.
+   *
+   * @param $name
+   *   The name of the header to retrieve.
+   * @return
+   *   The HTTP header value or FALSE if not found.
+   */
+  function drupalGetHeader($name) {
+    $headers = $this->drupalGetHeaders();
+    return isset($headers[$name]) ? $headers[$name] : FALSE;
+  }
+
+  /**
    * Gets the current raw HTML of requested page.
    */
   function drupalGetContent() {
Index: modules/simpletest/tests/bootstrap.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/bootstrap.test,v
retrieving revision 1.7
diff -u -p -r1.7 bootstrap.test
--- modules/simpletest/tests/bootstrap.test	23 Nov 2008 18:12:08 -0000	1.7
+++ modules/simpletest/tests/bootstrap.test	24 Nov 2008 18:14:42 -0000
@@ -104,7 +104,7 @@ class BootstrapPageCacheTestCase extends
     $this->drupalGet($base_url);
 
     $this->drupalHead($base_url);
-    $this->assertText('ETag: ', t('Verify presence of ETag header indicating that page caching is enabled.'));
+    $this->assertTrue($this->drupalGetHeader('ETag') !== FALSE, t('Verify presence of ETag header indicating that page caching is enabled.'));
   }
 
 }
Index: modules/simpletest/tests/session.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/session.test,v
retrieving revision 1.5
diff -u -p -r1.5 session.test
--- modules/simpletest/tests/session.test	24 Nov 2008 06:12:45 -0000	1.5
+++ modules/simpletest/tests/session.test	24 Nov 2008 18:14:42 -0000
@@ -8,8 +8,6 @@
 
 class SessionTestCase extends DrupalWebTestCase {
 
-  protected $saved_cookie;
-
   /**
    * Implementation of getInfo().
    */
@@ -27,17 +25,6 @@ class SessionTestCase extends DrupalWebT
   function setUp() {
     parent::setUp('session_test');
   }
-  /**
-   * Implementation of curlHeaderCallback().
-   */
-  protected function curlHeaderCallback($ch, $header) {
-    // Look for a Set-Cookie header.
-    if (preg_match('/^Set-Cookie.+$/i', $header, $matches)) {
-      $this->saved_cookie = $header;
-    }
-
-    return parent::curlHeaderCallback($ch, $header);
-  }
 
   /**
    * Tests for drupal_save_session() and drupal_session_regenerate().
@@ -55,7 +42,7 @@ class SessionTestCase extends DrupalWebT
     $this->sessionReset($user->uid);
     // Make sure the session cookie is set as HttpOnly.
     $this->drupalLogin($user);
-    $this->assertTrue(preg_match('/HttpOnly/i', $this->saved_cookie), t('Session cookie is set as HttpOnly.'));
+    $this->assertTrue(preg_match('/HttpOnly/i', $this->drupalGetHeader('Set-Cookie')), t('Session cookie is set as HttpOnly.'));
     $this->drupalLogout();
     // Verify that the session is regenerated if a module calls exit
     // in hook_user_login().
