Skip to content

Commit a9ccd32

Browse files
[HttpClient] Fix reading proxy settings from dotenv when curl is used
1 parent 4034240 commit a9ccd32

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

CurlHttpClient.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public function request(string $method, string $url, array $options = []): Respo
9292
$scheme = $url['scheme'];
9393
$authority = $url['authority'];
9494
$host = parse_url($authority, \PHP_URL_HOST);
95+
$proxy = $options['proxy']
96+
?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null : null)
97+
// Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
98+
?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null : null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null;
9599
$url = implode('', $url);
96100

97101
if (!isset($options['normalized_headers']['user-agent'])) {
@@ -107,7 +111,7 @@ public function request(string $method, string $url, array $options = []): Respo
107111
\CURLOPT_MAXREDIRS => 0 < $options['max_redirects'] ? $options['max_redirects'] : 0,
108112
\CURLOPT_COOKIEFILE => '', // Keep track of cookies during redirects
109113
\CURLOPT_TIMEOUT => 0,
110-
\CURLOPT_PROXY => $options['proxy'],
114+
\CURLOPT_PROXY => $proxy,
111115
\CURLOPT_NOPROXY => $options['no_proxy'] ?? $_SERVER['no_proxy'] ?? $_SERVER['NO_PROXY'] ?? '',
112116
\CURLOPT_SSL_VERIFYPEER => $options['verify_peer'],
113117
\CURLOPT_SSL_VERIFYHOST => $options['verify_host'] ? 2 : 0,
@@ -404,8 +408,15 @@ private static function createRedirectResolver(array $options, string $host): \C
404408
}
405409

406410
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));
411+
$url = self::resolveUrl($location, $url);
407412

408-
return implode('', self::resolveUrl($location, $url));
413+
curl_setopt($ch, \CURLOPT_PROXY, $options['proxy']
414+
?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null : null)
415+
// Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
416+
?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null : null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null
417+
);
418+
419+
return implode('', $url);
409420
};
410421
}
411422
}

0 commit comments

Comments
 (0)