Skip to content

Commit c23375b

Browse files
authored
Merge pull request #9021 from tangix/fix-curlrequest-version-option
fix: allow string as parameter to CURLRequest version
2 parents cd1f3f5 + c50ae9d commit c23375b

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

Diff for: system/HTTP/CURLRequest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,12 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
651651

652652
// version
653653
if (! empty($config['version'])) {
654-
if ($config['version'] === 1.0) {
654+
$version = sprintf('%.1F', $config['version']);
655+
if ($version === '1.0') {
655656
$curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
656-
} elseif ($config['version'] === 1.1) {
657+
} elseif ($version === '1.1') {
657658
$curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
658-
} elseif ($config['version'] === 2.0) {
659+
} elseif ($version === '2.0') {
659660
$curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2_0;
660661
}
661662
}

Diff for: tests/system/HTTP/CURLRequestTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -1227,4 +1227,34 @@ public function testGetHeaderLineContentType(): void
12271227

12281228
$this->assertSame('text/html; charset=UTF-8', $response->getHeaderLine('Content-Type'));
12291229
}
1230+
1231+
public function testHTTPversionAsString(): void
1232+
{
1233+
$this->request->request('POST', '/post', [
1234+
'version' => '1.0',
1235+
]);
1236+
1237+
$options = $this->request->curl_options;
1238+
1239+
$this->assertArrayHasKey(CURLOPT_HTTP_VERSION, $options);
1240+
$this->assertSame(CURL_HTTP_VERSION_1_0, $options[CURLOPT_HTTP_VERSION]);
1241+
1242+
$this->request->request('POST', '/post', [
1243+
'version' => '1.1',
1244+
]);
1245+
1246+
$options = $this->request->curl_options;
1247+
1248+
$this->assertArrayHasKey(CURLOPT_HTTP_VERSION, $options);
1249+
$this->assertSame(CURL_HTTP_VERSION_1_1, $options[CURLOPT_HTTP_VERSION]);
1250+
1251+
$this->request->request('POST', '/post', [
1252+
'version' => '2.0',
1253+
]);
1254+
1255+
$options = $this->request->curl_options;
1256+
1257+
$this->assertArrayHasKey(CURLOPT_HTTP_VERSION, $options);
1258+
$this->assertSame(CURL_HTTP_VERSION_2_0, $options[CURLOPT_HTTP_VERSION]);
1259+
}
12301260
}

Diff for: user_guide_src/source/changelogs/v4.5.4.rst

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Deprecations
3030
Bugs Fixed
3131
**********
3232

33+
- **CURLRequest:** Fixed a bug preventing the use of strings for ``version`` in the config array
34+
when making requests.
35+
3336
See the repo's
3437
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
3538
for a complete list of bugs fixed.

0 commit comments

Comments
 (0)