Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StreamHandler.php

function StreamHandler::resolveHost

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

File

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

Class

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

Namespace

GuzzleHttp\Handler

Code

private function resolveHost(RequestInterface $request, array $options) : UriInterface {
    $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 (false === $records || !isset($records[0]['ip'])) {
                throw new ConnectException(\sprintf("Could not resolve IPv4 address for host '%s'", $uri->getHost()), $request);
            }
            return $uri->withHost($records[0]['ip']);
        }
        if ('v6' === $options['force_ip_resolve']) {
            $records = \dns_get_record($uri->getHost(), \DNS_AAAA);
            if (false === $records || !isset($records[0]['ipv6'])) {
                throw new ConnectException(\sprintf("Could not resolve IPv6 address for host '%s'", $uri->getHost()), $request);
            }
            return $uri->withHost('[' . $records[0]['ipv6'] . ']');
        }
    }
    return $uri;
}
RSS feed
Powered by Drupal