You are here

protected function UpdateFetcher::doRequest in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/update/src/UpdateFetcher.php \Drupal\update\UpdateFetcher::doRequest()

Applies a GET request with a possible HTTP fallback.

This method falls back to HTTP in case there was some certificate problem.

Parameters

string $url: The URL.

array $options: The guzzle client options.

bool $with_http_fallback: Should the function fall back to HTTP.

Return value

string The body of the HTTP(S) request, or an empty string on failure.

File

core/modules/update/src/UpdateFetcher.php, line 92

Class

UpdateFetcher
Fetches project information from remote locations.

Namespace

Drupal\update

Code

protected function doRequest(string $url, array $options, bool $with_http_fallback) : string {
  $data = '';
  try {
    $data = (string) $this->httpClient
      ->get($url, [
      'headers' => [
        'Accept' => 'text/xml',
      ],
    ])
      ->getBody();
  } catch (TransferException $exception) {
    watchdog_exception('update', $exception);
    if ($with_http_fallback && strpos($url, "http://") === FALSE) {
      $url = str_replace('https://', 'http://', $url);
      return $this
        ->doRequest($url, $options, FALSE);
    }
  }
  return $data;
}