From d1998fc9cefc0cec5a2057f2df12c968108d0cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20M=C3=BCns?= Date: Mon, 29 Jun 2020 10:26:49 +0200 Subject: [PATCH 1/5] [FIX] Add http timeouts even if no http_proxy is used Fixes #1033 --- src/HttpClient/HttpClientFactory.php | 30 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/HttpClient/HttpClientFactory.php b/src/HttpClient/HttpClientFactory.php index 353557f17..4f465df12 100644 --- a/src/HttpClient/HttpClientFactory.php +++ b/src/HttpClient/HttpClientFactory.php @@ -110,22 +110,34 @@ public function create(Options $options): HttpAsyncClientInterface throw new \RuntimeException('The "http_proxy" option does not work together with a custom HTTP client.'); } - if (null === $httpClient && null !== $options->getHttpProxy()) { + if (null === $httpClient) { if (class_exists(GuzzleHttpClient::class)) { /** @psalm-suppress InvalidPropertyAssignmentValue */ - $httpClient = GuzzleHttpClient::createWithConfig([ - GuzzleHttpClientOptions::PROXY => $options->getHttpProxy(), + $guzzleConfig = [ GuzzleHttpClientOptions::TIMEOUT => self::DEFAULT_HTTP_TIMEOUT, GuzzleHttpClientOptions::CONNECT_TIMEOUT => self::DEFAULT_HTTP_CONNECT_TIMEOUT, - ]); - } elseif (class_exists(CurlHttpClient::class)) { + ]; + + if (null !== $options->getHttpProxy()) { + /** @psalm-suppress UndefinedClass */ + $guzzleConfig[GuzzleHttpClientOptions::PROXY] = $options->getHttpProxy(); + } + /** @psalm-suppress InvalidPropertyAssignmentValue */ - $httpClient = new CurlHttpClient($this->responseFactory, $this->streamFactory, [ - CURLOPT_PROXY => $options->getHttpProxy(), + $httpClient = GuzzleHttpClient::createWithConfig($guzzleConfig); + } elseif (class_exists(CurlHttpClient::class)) { + $curlConfig = [ CURLOPT_TIMEOUT => self::DEFAULT_HTTP_TIMEOUT, CURLOPT_CONNECTTIMEOUT => self::DEFAULT_HTTP_CONNECT_TIMEOUT, - ]); - } else { + ]; + + if (null !== $options->getHttpProxy()) { + $curlConfig[CURLOPT_PROXY] = $options->getHttpProxy(); + } + + /** @psalm-suppress InvalidPropertyAssignmentValue */ + $httpClient = new CurlHttpClient($this->responseFactory, $this->streamFactory, $curlConfig); + } elseif(null !== $options->getHttpProxy()) { throw new \RuntimeException('The "http_proxy" option requires either the "php-http/curl-client" or the "php-http/guzzle6-adapter" package to be installed.'); } } From 52bffa57e6c8a401b4c7cab0ebddd14d56067468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20M=C3=BCns?= Date: Mon, 29 Jun 2020 10:36:06 +0200 Subject: [PATCH 2/5] Fix PHP-CS-Fixer for HttpClientFactory.php --- src/HttpClient/HttpClientFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HttpClient/HttpClientFactory.php b/src/HttpClient/HttpClientFactory.php index 4f465df12..305408a9d 100644 --- a/src/HttpClient/HttpClientFactory.php +++ b/src/HttpClient/HttpClientFactory.php @@ -137,7 +137,7 @@ public function create(Options $options): HttpAsyncClientInterface /** @psalm-suppress InvalidPropertyAssignmentValue */ $httpClient = new CurlHttpClient($this->responseFactory, $this->streamFactory, $curlConfig); - } elseif(null !== $options->getHttpProxy()) { + } elseif (null !== $options->getHttpProxy()) { throw new \RuntimeException('The "http_proxy" option requires either the "php-http/curl-client" or the "php-http/guzzle6-adapter" package to be installed.'); } } From 58c68d16fb2c88f9043917d0e3f64dd27520bb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20M=C3=BCns?= Date: Mon, 29 Jun 2020 10:40:04 +0200 Subject: [PATCH 3/5] Fix Psalm for HttpClientFactory.php ERROR: UndefinedClass - src/HttpClient/HttpClientFactory.php:117:21 UndefinedClass - src/HttpClient/HttpClientFactory.php:118:21 --- src/HttpClient/HttpClientFactory.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/HttpClient/HttpClientFactory.php b/src/HttpClient/HttpClientFactory.php index 305408a9d..95d3ddd01 100644 --- a/src/HttpClient/HttpClientFactory.php +++ b/src/HttpClient/HttpClientFactory.php @@ -114,7 +114,9 @@ public function create(Options $options): HttpAsyncClientInterface if (class_exists(GuzzleHttpClient::class)) { /** @psalm-suppress InvalidPropertyAssignmentValue */ $guzzleConfig = [ + /** @psalm-suppress UndefinedClass */ GuzzleHttpClientOptions::TIMEOUT => self::DEFAULT_HTTP_TIMEOUT, + /** @psalm-suppress UndefinedClass */ GuzzleHttpClientOptions::CONNECT_TIMEOUT => self::DEFAULT_HTTP_CONNECT_TIMEOUT, ]; From 24ed386908f805eaf6d36f02d6b14c8799a4a5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20M=C3=BCns?= Date: Fri, 3 Jul 2020 10:06:29 +0200 Subject: [PATCH 4/5] Try to fix psalm for HttpClientFactory.php ERROR: UndefinedClass - src/HttpClient/HttpClientFactory.php:118:21 - Class or interface GuzzleHttp\RequestOptions does not exist (see https://psalm.dev/019) ERROR: UndefinedClass - src/HttpClient/HttpClientFactory.php:120:21 - Class or interface GuzzleHttp\RequestOptions does not exist (see https://psalm.dev/019) --- src/HttpClient/HttpClientFactory.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/HttpClient/HttpClientFactory.php b/src/HttpClient/HttpClientFactory.php index 95d3ddd01..d5abc7602 100644 --- a/src/HttpClient/HttpClientFactory.php +++ b/src/HttpClient/HttpClientFactory.php @@ -112,11 +112,9 @@ public function create(Options $options): HttpAsyncClientInterface if (null === $httpClient) { if (class_exists(GuzzleHttpClient::class)) { - /** @psalm-suppress InvalidPropertyAssignmentValue */ + /** @psalm-suppress UndefinedClass */ $guzzleConfig = [ - /** @psalm-suppress UndefinedClass */ GuzzleHttpClientOptions::TIMEOUT => self::DEFAULT_HTTP_TIMEOUT, - /** @psalm-suppress UndefinedClass */ GuzzleHttpClientOptions::CONNECT_TIMEOUT => self::DEFAULT_HTTP_CONNECT_TIMEOUT, ]; From cfd2e7f7b79783584592b080364bef1a1c563162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20M=C3=BCns?= Date: Fri, 3 Jul 2020 10:24:17 +0200 Subject: [PATCH 5/5] Add #1033 to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2bd3c160..3df675eb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix timeouts for connecting to the server and for the requests only being applied if a http proxy was specified (#1033) + ### 2.4.0 (2020-05-21) - Enforce a timeout for connecting to the server and for the requests instead of waiting indefinitely (#979)