You are here

protected function DrupalWebTestCase::drupalGetHeaders in Drupal 7

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.

Parameters

$all_requests: Boolean value specifying whether to return headers from all requests instead of just the last request. Defaults to FALSE.

Return value

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.

Values for duplicate headers are stored as a single comma-separated list.

4 calls to DrupalWebTestCase::drupalGetHeaders()
DrupalGotoTest::testDrupalGoto in modules/simpletest/tests/common.test
Test drupal_goto().
DrupalWebTestCase::drupalGetHeader in modules/simpletest/drupal_web_test_case.php
Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
FileDownloadTest::testPrivateFileTransfer in modules/simpletest/tests/file.test
Test the private file transfer system.
SimpleTestFunctionalTest::testInternalBrowser in modules/simpletest/simpletest.test
Test the internal browsers functionality.

File

modules/simpletest/drupal_web_test_case.php, line 3062

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected 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) {
        $name = ':status';
        $value = $header;
      }
      else {
        list($name, $value) = explode(':', $header, 2);
        $name = strtolower($name);
      }
      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;
}