← All changes
|
vendor_prefixed/guzzlehttp/guzzle/src/Handler/ProxyEnvironment.php
+0
-101
28.0
→
trunk
View file →
| @@ -1,101 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace YoastSEO_Vendor\GuzzleHttp\Handler; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * Resolves proxy configuration from the process environment with the same | |
| 7 | - * semantics libcurl applies, so the cURL handlers can pin CURLOPT_PROXY and | |
| 8 | - * CURLOPT_NOPROXY explicitly and libcurl never reads the environment itself. | |
| 9 | - * | |
| 10 | - * @internal | |
| 11 | - */ | |
| 12 | -final class ProxyEnvironment | |
| 13 | -{ | |
| 14 | - private function __construct() | |
| 15 | - { | |
| 16 | - } | |
| 17 | - /** | |
| 18 | - * Resolves the proxy to use for the given request scheme. | |
| 19 | - * | |
| 20 | - * The lookup mirrors libcurl for the http and https schemes the handlers | |
| 21 | - * accept: the lowercase scheme-specific variable first, its uppercase | |
| 22 | - * variant next (except for "http", where uppercase HTTP_PROXY is never | |
| 23 | - * read), then all_proxy/ALL_PROXY. | |
| 24 | - * | |
| 25 | - * @return string|null The proxy to use; null when the environment | |
| 26 | - * configures none. | |
| 27 | - */ | |
| 28 | - public static function getProxyForScheme(string $scheme) : ?string | |
| 29 | - { | |
| 30 | - $scheme = \strtolower($scheme); | |
| 31 | - $candidates = [$scheme . '_proxy']; | |
| 32 | - if ($scheme !== 'http') { | |
| 33 | - // Uppercase HTTP_PROXY is deliberately never consulted: a CGI | |
| 34 | - // request header "Proxy:" becomes HTTP_PROXY in the environment. | |
| 35 | - // See https://httpoxy.org for more information. | |
| 36 | - $candidates[] = \strtoupper($scheme) . '_PROXY'; | |
| 37 | - } | |
| 38 | - $candidates[] = 'all_proxy'; | |
| 39 | - $candidates[] = 'ALL_PROXY'; | |
| 40 | - foreach ($candidates as $name) { | |
| 41 | - $value = self::getenv($name); | |
| 42 | - if ($value !== null) { | |
| 43 | - return $value; | |
| 44 | - } | |
| 45 | - } | |
| 46 | - return null; | |
| 47 | - } | |
| 48 | - /** | |
| 49 | - * @return string|null The no-proxy list; null when nothing is set. | |
| 50 | - */ | |
| 51 | - public static function getNoProxy() : ?string | |
| 52 | - { | |
| 53 | - foreach (['no_proxy', 'NO_PROXY'] as $name) { | |
| 54 | - $value = self::getenv($name); | |
| 55 | - if ($value !== null) { | |
| 56 | - return $value; | |
| 57 | - } | |
| 58 | - } | |
| 59 | - return null; | |
| 60 | - } | |
| 61 | - /** | |
| 62 | - * Splits a no_proxy environment value into matchable entries. | |
| 63 | - * | |
| 64 | - * Mirrors libcurl's tokenization: entries may be separated by commas or | |
| 65 | - * blanks, and a single leading dot is ignored, so ".example.com" bypasses | |
| 66 | - * example.com and its subdomains exactly as a bare domain entry does. | |
| 67 | - * | |
| 68 | - * @return string[] | |
| 69 | - */ | |
| 70 | - public static function splitNoProxy(string $noProxy) : array | |
| 71 | - { | |
| 72 | - $entries = []; | |
| 73 | - foreach (\preg_split('/[\\s,]+/', $noProxy) ?: [] as $entry) { | |
| 74 | - if ($entry !== '' && $entry[0] === '.') { | |
| 75 | - $entry = \substr($entry, 1); | |
| 76 | - } | |
| 77 | - if ($entry !== '') { | |
| 78 | - $entries[] = $entry; | |
| 79 | - } | |
| 80 | - } | |
| 81 | - return $entries; | |
| 82 | - } | |
| 83 | - private static function getenv(string $name) : ?string | |
| 84 | - { | |
| 85 | - // Windows environment variables are case-insensitive, so the | |
| 86 | - // lowercase-only httpoxy defence does not hold there. Outside the | |
| 87 | - // CLI SAPI on Windows, environment proxies are not resolved at all | |
| 88 | - // (a safe-side divergence from libcurl). | |
| 89 | - if (\PHP_OS_FAMILY === 'Windows' && \PHP_SAPI !== 'cli') { | |
| 90 | - return null; | |
| 91 | - } | |
| 92 | - // local_only: the OS environment and putenv() only - the same | |
| 93 | - // environ(7) libcurl reads. SAPI request environments such as | |
| 94 | - // fastcgi_param or SetEnv are deliberately excluded. | |
| 95 | - $value = \getenv($name, \true); | |
| 96 | - // libcurl's GetEnv (lib/getenv.c) treats variables set to an empty | |
| 97 | - // string as unset on every version, so the lookup falls through to | |
| 98 | - // the next candidate. | |
| 99 | - return $value === \false || $value === '' ? null : $value; | |
| 100 | - } | |
| 101 | -} | |