Index: drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.2.2.3.2.21
diff -u -p -r1.2.2.3.2.21 drupal_web_test_case.php
--- drupal_web_test_case.php	14 Nov 2008 18:49:16 -0000	1.2.2.3.2.21
+++ drupal_web_test_case.php	23 Nov 2008 18:26:48 -0000
@@ -6,6 +6,7 @@
  */
 class DrupalWebTestCase {
   protected $_logged_in = FALSE;
+  protected $_headers;
   protected $_content;
   protected $plain_text;
   protected $ch;
@@ -788,7 +789,8 @@ class DrupalWebTestCase {
         CURLOPT_FOLLOWLOCATION => TRUE,
         CURLOPT_RETURNTRANSFER => TRUE,
         CURLOPT_SSL_VERIFYPEER => FALSE,
-		CURLOPT_SSL_VERIFYHOST => FALSE,
+        CURLOPT_SSL_VERIFYHOST => FALSE,
+        CURLOPT_HEADERFUNCTION => array($this, 'curlHeaderCallback'),
       );
       if (preg_match('/simpletest\d+/', $db_prefix)) {
         $curl_options[CURLOPT_USERAGENT] = $db_prefix;
@@ -815,6 +817,7 @@ class DrupalWebTestCase {
     $this->curlConnect();
     $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->_content = curl_exec($this->ch);
     $this->plain_text = FALSE;
     $this->elements = FALSE;
@@ -823,6 +826,14 @@ class DrupalWebTestCase {
   }
 
   /**
+   * Saves HTTP response headers to the _headers array.
+   */
+  protected function curlHeaderCallback($ch, $header) {
+    $this->_headers[] = $header;
+    return strlen($header);
+  }
+
+  /**
    * Close the cURL handler and unset the handler.
    */
   protected function curlClose() {
@@ -1292,6 +1303,63 @@ class DrupalWebTestCase {
   }
 
   /**
+   * Gets the HTTP response headers.
+   *
+   * @param $all_requests
+   *   - If TRUE, return headers for all requests, including intermediate HTTP
+   *     redirects etc.
+   *   - If FALSE, return only headers from the last request.
+   * @return
+   *   - If $all_requests is FALSE, the HTTP headers are returned in a name =>
+   *     value array.
+   *   - If $all_requests is TRUE, the return value is an array of name => value
+   *     arrays, one for each request.
+   */
+  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-Line', $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 the specified HTTP response. If there were multiple
+   * requests due to e.g. HTTP redirects, only headers from the final request
+   * are returned.
+   *
+   * @param $name
+   *   The HTTP header name.
+   * @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() {
