From a9b42fedbec77770b135d363973c3dcf8b07f4b4 Mon Sep 17 00:00:00 2001 From: Mattias Sandstrom <1013635+tangix@users.noreply.github.com> Date: Thu, 4 Jul 2024 07:17:07 +0200 Subject: [PATCH 1/7] Allow string as parameter to version As indicated in the docs. --- system/HTTP/CURLRequest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 4b1c9c625399..2305c7f993ea 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -651,11 +651,11 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) // version if (! empty($config['version'])) { - if ($config['version'] === 1.0) { + if ($config['version'] === 1.0 || $config['version'] === "1.0") { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; - } elseif ($config['version'] === 1.1) { + } elseif ($config['version'] === 1.1 || $config['version'] === "1.1") { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; - } elseif ($config['version'] === 2.0) { + } elseif ($config['version'] === 2.0 || $config['version'] === "2.0") { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0; } } From 20c5c21142130d3e89b73d9d6d50c11ab210ca8a Mon Sep 17 00:00:00 2001 From: Mattias Sandstrom <1013635+tangix@users.noreply.github.com> Date: Thu, 4 Jul 2024 07:24:05 +0200 Subject: [PATCH 2/7] Ran CS fixer --- system/HTTP/CURLRequest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 2305c7f993ea..89adb498b003 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -651,11 +651,11 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) // version if (! empty($config['version'])) { - if ($config['version'] === 1.0 || $config['version'] === "1.0") { + if ($config['version'] === 1.0 || $config['version'] === '1.0') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; - } elseif ($config['version'] === 1.1 || $config['version'] === "1.1") { + } elseif ($config['version'] === 1.1 || $config['version'] === '1.1') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; - } elseif ($config['version'] === 2.0 || $config['version'] === "2.0") { + } elseif ($config['version'] === 2.0 || $config['version'] === '2.0') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0; } } From 409aa66f155999ff0699bf9b8db373e0f464e928 Mon Sep 17 00:00:00 2001 From: Mattias Sandstrom <1013635+tangix@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:00:17 +0200 Subject: [PATCH 3/7] Added tests for all versions --- tests/system/HTTP/CURLRequestTest.php | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index dc48eb621d80..bd05852a781f 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -1227,4 +1227,35 @@ public function testGetHeaderLineContentType(): void $this->assertSame('text/html; charset=UTF-8', $response->getHeaderLine('Content-Type')); } + + public function testHTTPversionAsString(): void + { + $this->request->request('POST', '/post', [ + 'version' => '1.0', + ]); + + $options = $this->request->curl_options; + + $this->assertArrayHasKey(CURLOPT_HTTP_VERSION, $options); + $this->assertSame(CURL_HTTP_VERSION_1_0, $options[CURLOPT_HTTP_VERSION]); + + $this->request->request('POST', '/post', [ + 'version' => '1.1', + ]); + + $options = $this->request->curl_options; + + $this->assertArrayHasKey(CURLOPT_HTTP_VERSION, $options); + $this->assertSame(CURL_HTTP_VERSION_1_1, $options[CURLOPT_HTTP_VERSION]); + + $this->request->request('POST', '/post', [ + 'version' => '2.0', + ]); + + $options = $this->request->curl_options; + + $this->assertArrayHasKey(CURLOPT_HTTP_VERSION, $options); + $this->assertSame(CURL_HTTP_VERSION_2_0, $options[CURLOPT_HTTP_VERSION]); + + } } From da57987f54543fa84ad2975ab8c1ed83110471e4 Mon Sep 17 00:00:00 2001 From: Mattias Sandstrom <1013635+tangix@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:03:30 +0200 Subject: [PATCH 4/7] Fixed code style --- tests/system/HTTP/CURLRequestTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index bd05852a781f..f14198be2264 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -1256,6 +1256,5 @@ public function testHTTPversionAsString(): void $this->assertArrayHasKey(CURLOPT_HTTP_VERSION, $options); $this->assertSame(CURL_HTTP_VERSION_2_0, $options[CURLOPT_HTTP_VERSION]); - } } From fd16faf1473fc538d1082909fb60541b42143efc Mon Sep 17 00:00:00 2001 From: Mattias Sandstrom <1013635+tangix@users.noreply.github.com> Date: Thu, 4 Jul 2024 18:07:03 +0200 Subject: [PATCH 5/7] Updated logic to convert to string for comparison --- system/HTTP/CURLRequest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 89adb498b003..9f405a7c1667 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -651,11 +651,12 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) // version if (! empty($config['version'])) { - if ($config['version'] === 1.0 || $config['version'] === '1.0') { + $version = sprintf('%.1f', $config['version']); + if ($version === '1.0') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; - } elseif ($config['version'] === 1.1 || $config['version'] === '1.1') { + } elseif ($version === '1.1') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; - } elseif ($config['version'] === 2.0 || $config['version'] === '2.0') { + } elseif ($version === '2.0') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0; } } From a6a50cc538744f32dfca5e59232093270a7c3713 Mon Sep 17 00:00:00 2001 From: Mattias Sandstrom <1013635+tangix@users.noreply.github.com> Date: Thu, 4 Jul 2024 19:08:44 +0200 Subject: [PATCH 6/7] Added info to change-log --- user_guide_src/source/changelogs/v4.5.4.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/user_guide_src/source/changelogs/v4.5.4.rst b/user_guide_src/source/changelogs/v4.5.4.rst index bf737a99a335..51a9fd74f407 100644 --- a/user_guide_src/source/changelogs/v4.5.4.rst +++ b/user_guide_src/source/changelogs/v4.5.4.rst @@ -30,6 +30,9 @@ Deprecations Bugs Fixed ********** +- **CURLRequest:** Fixed a bug preventing the use of strings for ``version`` in the config array + when making requests. + See the repo's `CHANGELOG.md `_ for a complete list of bugs fixed. From c50ae9da47531f44703f52e5964440ed4e2529ec Mon Sep 17 00:00:00 2001 From: Mattias Sandstrom <1013635+tangix@users.noreply.github.com> Date: Fri, 5 Jul 2024 08:01:05 +0200 Subject: [PATCH 7/7] Fixing locale-aware issue --- system/HTTP/CURLRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 9f405a7c1667..9da231c17716 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -651,7 +651,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = []) // version if (! empty($config['version'])) { - $version = sprintf('%.1f', $config['version']); + $version = sprintf('%.1F', $config['version']); if ($version === '1.0') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; } elseif ($version === '1.1') {