You are here

private function StreamHandler::resolveHost in Lockr 7.3

1 call to StreamHandler::resolveHost()
StreamHandler::createStream in vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php

File

vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php, line 338

Class

StreamHandler
HTTP handler that uses PHP's HTTP stream wrapper.

Namespace

GuzzleHttp\Handler

Code

private function resolveHost(RequestInterface $request, array $options) {
  $uri = $request
    ->getUri();
  if (isset($options['force_ip_resolve']) && !filter_var($uri
    ->getHost(), FILTER_VALIDATE_IP)) {
    if ('v4' === $options['force_ip_resolve']) {
      $records = dns_get_record($uri
        ->getHost(), DNS_A);
      if (!isset($records[0]['ip'])) {
        throw new ConnectException(sprintf("Could not resolve IPv4 address for host '%s'", $uri
          ->getHost()), $request);
      }
      $uri = $uri
        ->withHost($records[0]['ip']);
    }
    elseif ('v6' === $options['force_ip_resolve']) {
      $records = dns_get_record($uri
        ->getHost(), DNS_AAAA);
      if (!isset($records[0]['ipv6'])) {
        throw new ConnectException(sprintf("Could not resolve IPv6 address for host '%s'", $uri
          ->getHost()), $request);
      }
      $uri = $uri
        ->withHost('[' . $records[0]['ipv6'] . ']');
    }
  }
  return $uri;
}