Skip to content

Commit 7a3fda8

Browse files
Merge branch '5.4' into 6.2
* 5.4: [HttpClient] fix proxied redirects in curl client [Intl] Update the ICU data to 73.1 [Console] Restoring the ability to output unicode text to the Win10 console [Mailer] Add brifge documentation
2 parents 7daf5d2 + 279f53a commit 7a3fda8

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

CurlHttpClient.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ public function request(string $method, string $url, array $options = []): Respo
8989
$authority = $url['authority'];
9090
$host = parse_url($authority, \PHP_URL_HOST);
9191
$port = parse_url($authority, \PHP_URL_PORT) ?: ('http:' === $scheme ? 80 : 443);
92-
$proxy = $options['proxy']
93-
?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null : null)
94-
// Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
95-
?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null : null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null;
92+
$proxy = self::getProxyUrl($options['proxy'], $url);
9693
$url = implode('', $url);
9794

9895
if (!isset($options['normalized_headers']['user-agent'])) {
@@ -400,7 +397,7 @@ private static function createRedirectResolver(array $options, string $host, int
400397
}
401398
}
402399

403-
return static function ($ch, string $location, bool $noContent) use (&$redirectHeaders) {
400+
return static function ($ch, string $location, bool $noContent) use (&$redirectHeaders, $options) {
404401
try {
405402
$location = self::parseUrl($location);
406403
} catch (InvalidArgumentException) {
@@ -426,11 +423,7 @@ private static function createRedirectResolver(array $options, string $host, int
426423
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
427424
$url = self::resolveUrl($location, $url);
428425

429-
curl_setopt($ch, \CURLOPT_PROXY, $options['proxy']
430-
?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null : null)
431-
// Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
432-
?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null : null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null
433-
);
426+
curl_setopt($ch, \CURLOPT_PROXY, self::getProxyUrl($options['proxy'], $url));
434427

435428
return implode('', $url);
436429
};

HttpClientTrait.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,16 +648,7 @@ private static function mergeQueryString(?string $queryString, array $queryArray
648648
*/
649649
private static function getProxy(?string $proxy, array $url, ?string $noProxy): ?array
650650
{
651-
if (null === $proxy) {
652-
// Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
653-
$proxy = $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null : null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null;
654-
655-
if ('https:' === $url['scheme']) {
656-
$proxy = $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? $proxy;
657-
}
658-
}
659-
660-
if (null === $proxy) {
651+
if (null === $proxy = self::getProxyUrl($proxy, $url)) {
661652
return null;
662653
}
663654

@@ -685,6 +676,22 @@ private static function getProxy(?string $proxy, array $url, ?string $noProxy):
685676
];
686677
}
687678

679+
private static function getProxyUrl(?string $proxy, array $url): ?string
680+
{
681+
if (null !== $proxy) {
682+
return $proxy;
683+
}
684+
685+
// Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
686+
$proxy = $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null : null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null;
687+
688+
if ('https:' === $url['scheme']) {
689+
$proxy = $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? $proxy;
690+
}
691+
692+
return $proxy;
693+
}
694+
688695
private static function shouldBuffer(array $headers): bool
689696
{
690697
if (null === $contentType = $headers['content-type'][0] ?? null) {

0 commit comments

Comments
 (0)