Skip to content

Commit

Permalink
Merge pull request #9021 from tangix/fix-curlrequest-version-option
Browse files Browse the repository at this point in the history
fix: allow string as parameter to CURLRequest version
  • Loading branch information
kenjis authored Jul 7, 2024
2 parents cd1f3f5 + c50ae9d commit c23375b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
7 changes: 4 additions & 3 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
3 changes: 3 additions & 0 deletions user_guide_src/source/changelogs/v4.5.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
for a complete list of bugs fixed.

0 comments on commit c23375b

Please sign in to comment.