You are here

protected function PageCacheTest::getHeaders in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::getHeaders()
  2. 9 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.

File

core/modules/page_cache/tests/src/Functional/PageCacheTest.php, line 599

Class

PageCacheTest
Enables the page cache and tests it with various HTTP requests.

Namespace

Drupal\Tests\page_cache\Functional

Code

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