function PageCacheTest::getHeaders
Same name in other branches
- 9 core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::getHeaders()
- 9 core/modules/hal/tests/src/Functional/page_cache/PageCacheTest.php \Drupal\Tests\hal\Functional\page_cache\PageCacheTest::getHeaders()
- 8.9.x core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::getHeaders()
- 11.x core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::getHeaders()
Retrieves only the headers for an absolute path.
Executes a cURL request without any modifications to the given URL. Note that Guzzle always normalizes URLs which prevents testing all possible edge cases.
Parameters
string $url: URL to request.
Return value
array Array of headers.
1 call to PageCacheTest::getHeaders()
- PageCacheTest::testNoUrlNormalization in core/
modules/ page_cache/ tests/ src/ Functional/ PageCacheTest.php - Tests that URLs are cached in a not normalized form.
File
-
core/
modules/ page_cache/ tests/ src/ Functional/ PageCacheTest.php, line 646
Class
- PageCacheTest
- Enables the page cache and tests it with various HTTP requests.
Namespace
Drupal\Tests\page_cache\FunctionalCode
protected function getHeaders($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, drupal_generate_test_ua($this->databasePrefix));
$output = curl_exec($ch);
curl_close($ch);
$headers = [];
foreach (explode("\n", $output) as $header) {
if (strpos($header, ':')) {
[
$key,
$value,
] = explode(':', $header, 2);
$headers[trim($key)] = trim($value);
}
}
return $headers;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.