diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 4b1c9c625399..9da231c17716 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) { + $version = sprintf('%.1F', $config['version']); + if ($version === '1.0') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0; - } elseif ($config['version'] === 1.1) { + } elseif ($version === '1.1') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; - } elseif ($config['version'] === 2.0) { + } elseif ($version === '2.0') { $curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0; } } diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index dc48eb621d80..f14198be2264 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -1227,4 +1227,34 @@ 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]); + } } 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.