protected function WebTestBase::drupalGetHeaders

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.

6 calls to WebTestBase::drupalGetHeaders()
DownloadTest::testPrivateFileTransfer in drupal/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php
Test the private file transfer system.
GotoTest::testDrupalGoto in drupal/core/modules/system/lib/Drupal/system/Tests/Common/GotoTest.php
Tests drupal_goto().
RESTTestBase::httpRequest in drupal/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php
Helper function to issue a HTTP request with simpletest's cURL.
SimpleTestTest::testInternalBrowser in drupal/core/modules/simpletest/lib/Drupal/simpletest/Tests/SimpleTestTest.php
Test the internal browsers functionality.
StyleSerializerTest::testSerializerResponses in drupal/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php
Checks the behavior of the Serializer callback paths and row plugins.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php, line 2139
Definition of Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

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;
}