function WebTestBase::drupalGetHeader

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 from last to first until the header is found.

Parameters

$name: The name of the header to retrieve. Names are case-insensitive (see RFC 2616 section 4.2).

$all_requests: Boolean value specifying whether to check all requests if the header is not found in the last request. Defaults to FALSE.

Return value

The HTTP header value or FALSE if not found.

10 calls to WebTestBase::drupalGetHeader()
BrowserTest::testCookies in core/modules/simpletest/src/Tests/BrowserTest.php
Tests that cookies set during a request are available for testing.
EntityCacheTagsTestBase::testReferencedEntity in core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity when referenced.
PageCacheTagsTestBase::verifyPageCache in core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php
Verify that when loading a given page, it's a page cache hit or miss.
RESTTestBase::drupalGetHeader in core/modules/rest/src/Tests/RESTTestBase.php
Gets the value of an HTTP response header.
SimpleTestBrowserTest::testInternalBrowser in core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php
Test the internal browsers functionality.

... See full list

1 method overrides WebTestBase::drupalGetHeader()
RESTTestBase::drupalGetHeader in core/modules/rest/src/Tests/RESTTestBase.php
Gets the value of an HTTP response header.

File

core/modules/simpletest/src/WebTestBase.php, line 1865

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function drupalGetHeader($name, $all_requests = FALSE) {
    $name = strtolower($name);
    $header = FALSE;
    if ($all_requests) {
        foreach (array_reverse($this->drupalGetHeaders(TRUE)) as $headers) {
            if (isset($headers[$name])) {
                $header = $headers[$name];
                break;
            }
        }
    }
    else {
        $headers = $this->drupalGetHeaders();
        if (isset($headers[$name])) {
            $header = $headers[$name];
        }
    }
    return $header;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.