You are here

protected function SecurityAdvisoriesFetcher::doRequest in Drupal 9

Makes an HTTPS GET request, with a possible HTTP fallback.

This method will fall back to HTTP if the HTTPS request fails and the site setting 'update_fetch_with_http_fallback' is set to TRUE.

Parameters

int $timeout: The timeout in seconds for the request.

Return value

string The response.

1 call to SecurityAdvisoriesFetcher::doRequest()
SecurityAdvisoriesFetcher::getSecurityAdvisories in core/modules/system/src/SecurityAdvisories/SecurityAdvisoriesFetcher.php
Gets security advisories that are applicable for the current site.

File

core/modules/system/src/SecurityAdvisories/SecurityAdvisoriesFetcher.php, line 312

Class

SecurityAdvisoriesFetcher
Defines a service to get security advisories.

Namespace

Drupal\system\SecurityAdvisories

Code

protected function doRequest(int $timeout) : string {
  $options = [
    RequestOptions::TIMEOUT => $timeout,
  ];
  if (!$this->withHttpFallback) {

    // If not using an HTTP fallback just use HTTPS and do not catch any
    // exceptions.
    $response = $this->httpClient
      ->get('https://updates.drupal.org/psa.json', $options);
  }
  else {
    try {
      $response = $this->httpClient
        ->get('https://updates.drupal.org/psa.json', $options);
    } catch (TransferException $exception) {
      watchdog_exception('system', $exception);
      $response = $this->httpClient
        ->get('http://updates.drupal.org/psa.json', $options);
    }
  }
  return (string) $response
    ->getBody();
}