From 7e0cd4e62135d2e7f9260901dbdb098660c876b4 Mon Sep 17 00:00:00 2001 From: Bohan Yang Date: Thu, 1 Oct 2020 18:50:45 +0800 Subject: [PATCH] [HttpClient] Fix using https with proxies --- src/Symfony/Component/HttpClient/NativeHttpClient.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpClient/NativeHttpClient.php b/src/Symfony/Component/HttpClient/NativeHttpClient.php index ac6ee58246..9fcfb4ad2a 100644 --- a/src/Symfony/Component/HttpClient/NativeHttpClient.php +++ b/src/Symfony/Component/HttpClient/NativeHttpClient.php @@ -225,7 +225,7 @@ final class NativeHttpClient implements HttpClientInterface, LoggerAwareInterfac $resolveRedirect = self::createRedirectResolver($options, $host, $proxy, $noProxy, $info, $onProgress); $context = stream_context_create($context, ['notification' => $notification]); - self::configureHeadersAndProxy($context, $host, $options['headers'], $proxy, $noProxy); + self::configureHeadersAndProxy($context, $host, $options['headers'], $proxy, $noProxy, 'https:' === $url['scheme']); return new NativeResponse($this->multi, $context, implode('', $url), $options, $info, $resolveRedirect, $onProgress, $this->logger); } @@ -411,14 +411,14 @@ final class NativeHttpClient implements HttpClientInterface, LoggerAwareInterfac // Authorization and Cookie headers MUST NOT follow except for the initial host name $requestHeaders = $redirectHeaders['host'] === $host ? $redirectHeaders['with_auth'] : $redirectHeaders['no_auth']; $requestHeaders[] = 'Host: '.$host.$port; - self::configureHeadersAndProxy($context, $host, $requestHeaders, $proxy, $noProxy); + self::configureHeadersAndProxy($context, $host, $requestHeaders, $proxy, $noProxy, 'https:' === $url['scheme']); } return implode('', $url); }; } - private static function configureHeadersAndProxy($context, string $host, array $requestHeaders, ?array $proxy, array $noProxy) + private static function configureHeadersAndProxy($context, string $host, array $requestHeaders, ?array $proxy, array $noProxy, bool $isSsl) { if (null === $proxy) { return stream_context_set_option($context, 'http', 'header', $requestHeaders); @@ -435,7 +435,7 @@ final class NativeHttpClient implements HttpClientInterface, LoggerAwareInterfac } stream_context_set_option($context, 'http', 'proxy', $proxy['url']); - stream_context_set_option($context, 'http', 'request_fulluri', true); + stream_context_set_option($context, 'http', 'request_fulluri', !$isSsl); if (null !== $proxy['auth']) { $requestHeaders[] = 'Proxy-Authorization: '.$proxy['auth'];