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

Breadcrumb

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

function StreamHandler::parse_proxy

Parses the given proxy URL to make it compatible with the format PHP's stream context expects.

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

File

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

Class

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

Namespace

GuzzleHttp\Handler

Code

private function parse_proxy(string $url) : array {
    $parsed = \parse_url($url);
    if ($parsed !== false && isset($parsed['scheme']) && $parsed['scheme'] === 'http') {
        if (isset($parsed['host']) && isset($parsed['port'])) {
            $auth = null;
            if (isset($parsed['user']) && isset($parsed['pass'])) {
                $auth = \base64_encode("{$parsed['user']}:{$parsed['pass']}");
            }
            return [
                'proxy' => "tcp://{$parsed['host']}:{$parsed['port']}",
                'auth' => $auth ? "Basic {$auth}" : null,
            ];
        }
    }
    // Return proxy as-is.
    return [
        'proxy' => $url,
        'auth' => null,
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal