protected function PageCacheTest::getHeaders in Drupal 9
Same name and namespace in other branches
- 8 core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::getHeaders()
- 10 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 641
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, ':')) {
list($key, $value) = explode(':', $header, 2);
$headers[trim($key)] = trim($value);
}
}
return $headers;
}