You are here

class TestHttpClientFactory in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 src/Tests/TestHttpClientFactory.php \Drupal\salesforce\Tests\TestHttpClientFactory
  2. 5.0.x src/Tests/TestHttpClientFactory.php \Drupal\salesforce\Tests\TestHttpClientFactory

Helper class to construct a HTTP client with Drupal specific config.

Hierarchy

Expanded class hierarchy of TestHttpClientFactory

1 file declares its use of TestHttpClientFactory
SalesforceTestRestClientServiceProvider.php in tests/modules/salesforce_test_rest_client/src/SalesforceTestRestClientServiceProvider.php

File

src/Tests/TestHttpClientFactory.php, line 12

Namespace

Drupal\salesforce\Tests
View source
class TestHttpClientFactory extends ClientFactory {

  /**
   * Constructs a new client object from some configuration.
   *
   * @param array $config
   *   The config for the client.
   *
   * @return \GuzzleHttp\Client
   *   The HTTP client.
   */
  public function fromOptions(array $config = []) {
    $default_config = [
      // Security consideration: we must not use the certificate authority
      // file shipped with Guzzle because it can easily get outdated if a
      // certificate authority is hacked. Instead, we rely on the certificate
      // authority file provided by the operating system which is more likely
      // going to be updated in a timely fashion. This overrides the default
      // path to the pem file bundled with Guzzle.
      'verify' => TRUE,
      'timeout' => 30,
      'headers' => [
        'User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent(),
      ],
      'handler' => $this->stack,
      // Security consideration: prevent Guzzle from using environment variables
      // to configure the outbound proxy.
      'proxy' => [
        'http' => NULL,
        'https' => NULL,
        'no' => [],
      ],
    ];
    $config = NestedArray::mergeDeep($default_config, Settings::get('http_client_config', []), $config);
    return new TestHttpClient($config);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClientFactory::$stack protected property The handler stack.
ClientFactory::__construct public function Constructs a new ClientFactory instance.
TestHttpClientFactory::fromOptions public function Constructs a new client object from some configuration. Overrides ClientFactory::fromOptions