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

Breadcrumb

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

function Utils::isHostInNoProxy

Returns true if the provided host matches any of the no proxy areas.

This method will strip a port from the host if it is present. Each pattern can be matched with an exact match (e.g., "foo.com" == "foo.com") or a partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" == "baz.foo.com", but ".foo.com" != "foo.com").

Areas are matched in the following cases: 1. "*" (without quotes) always matches any hosts. 2. An exact match. 3. The area starts with "." and the area is the last part of the host. e.g. '.mit.edu' will match any host that ends with '.mit.edu'.

Parameters

string $host Host to check against the patterns.:

string[] $noProxyArray An array of host patterns.:

Throws

InvalidArgumentException

3 calls to Utils::isHostInNoProxy()
CurlFactory::applyHandlerOptions in vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php
is_host_in_noproxy in vendor/guzzlehttp/guzzle/src/functions.php
Returns true if the provided host matches any of the no proxy areas.
StreamHandler::add_proxy in vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php

File

vendor/guzzlehttp/guzzle/src/Utils.php, line 223

Class

Utils

Namespace

GuzzleHttp

Code

public static function isHostInNoProxy(string $host, array $noProxyArray) : bool {
    if (\strlen($host) === 0) {
        throw new InvalidArgumentException('Empty host provided');
    }
    // Strip port if present.
    [
        $host,
    ] = \explode(':', $host, 2);
    foreach ($noProxyArray as $area) {
        // Always match on wildcards.
        if ($area === '*') {
            return true;
        }
        if (empty($area)) {
            // Don't match on empty values.
            continue;
        }
        if ($area === $host) {
            // Exact matches.
            return true;
        }
        // Special match if the area when prefixed with ".". Remove any
        // existing leading "." and add a new leading ".".
        $area = '.' . \ltrim($area, '.');
        if (\substr($host, -\strlen($area)) === $area) {
            return true;
        }
    }
    return false;
}
RSS feed
Powered by Drupal