function SecurityAdvisoriesFetcher::doRequest

Same name in other branches
  1. 9 core/modules/system/src/SecurityAdvisories/SecurityAdvisoriesFetcher.php \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher::doRequest()
  2. 11.x core/modules/system/src/SecurityAdvisories/SecurityAdvisoriesFetcher.php \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher::doRequest()

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 313

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 (ClientExceptionInterface $exception) {
            Error::logException($this->logger, $exception);
            $response = $this->httpClient
                ->get('http://updates.drupal.org/psa.json', $options);
        }
    }
    return (string) $response->getBody();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.