Skip to content

Commit e4bbf9d

Browse files
feature #489 [PHP 8.4] Add CURL_HTTP_VERSION_3(ONLY) constants (Ayesh)
This PR was merged into the 1.x branch. Discussion ---------- [PHP 8.4] Add `CURL_HTTP_VERSION_3(ONLY)` constants If the underlying Curl build supports it, setting the HTTP version should be theoretically possible. The availability of the constants do not guarantee the feature support, so declaring them in the polyfill should be same and effective. - PR that added constants: [php-src#15350](php/php-src#15350) - libcurl doc on `CURLOPT_HTTP_VERSION`](https://curl.se/libcurl/c/CURLOPT_HTTP_VERSION.html) - [PHP.Watch: HTTP/3 Request with PHP Curl Extension](https://php.watch/articles/php-curl-http3) - Codex for [`CURL_HTTP_VERSION_3`](https://php.watch/codex/CURL_HTTP_VERSION_3) and [`CURL_HTTP_VERSION_3ONLY`](https://php.watch/codex/CURL_HTTP_VERSION_3ONLY) Fixes GH-488. Commits ------- 8323493 [PHP 8.4] Add `CURL_HTTP_VERSION_3(ONLY)` constants
2 parents 1419e0d + 8323493 commit e4bbf9d

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Polyfills are provided for:
7171
- the `array_find`, `array_find_key`, `array_any` and `array_all` functions introduced in PHP 8.4;
7272
- the `Deprecated` attribute introduced in PHP 8.4;
7373
- the `mb_trim`, `mb_ltrim` and `mb_rtrim` functions introduced in PHP 8.4;
74+
- the `CURL_HTTP_VERSION_3` and `CURL_HTTP_VERSION_3ONLY` constants introduced in PHP 8.4;
7475

7576
It is strongly recommended to upgrade your PHP version and/or install the missing
7677
extensions whenever possible. This polyfill should be used only when there is no

src/Php84/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This component provides features added to PHP 8.4 core:
66
- [`mb_ucfirst` and `mb_lcfirst`](https://wiki.php.net/rfc/mb_ucfirst)
77
- [`array_find`, `array_find_key`, `array_any` and `array_all`](https://wiki.php.net/rfc/array_find)
88
- [`Deprecated`](https://wiki.php.net/rfc/deprecated_attribute)
9+
- `CURL_HTTP_VERSION_3` and `CURL_HTTP_VERSION_3ONLY` constants
910

1011
More information can be found in the
1112
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).

src/Php84/bootstrap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
return;
1616
}
1717

18+
if (defined('CURL_VERSION_HTTP3') || PHP_VERSION_ID < 80200 && function_exists('curl_version') && curl_version()['version'] >= 0x074200) { // libcurl >= 7.66.0
19+
define('CURL_HTTP_VERSION_3', 30);
20+
21+
if (defined('CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256')) { // libcurl >= 7.80.0 (7.88 would be better but is slow to check)
22+
define('CURL_HTTP_VERSION_3ONLY', 31);
23+
}
24+
}
25+
1826
if (!function_exists('array_find')) {
1927
function array_find(array $array, callable $callback) { return p\Php84::array_find($array, $callback); }
2028
}

tests/Php84/Php84Test.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ public function testArrayAll(array $array, callable $callback, bool $expected)
6464
$this->assertSame($expected, array_all($array, $callback));
6565
}
6666

67+
/**
68+
* @requires extension curl
69+
*/
70+
public function testCurlHttp3Constants()
71+
{
72+
$ch = curl_init();
73+
$hasH3 = defined('CURL_VERSION_HTTP3') && (curl_version()['features'] & CURL_VERSION_HTTP3);
74+
75+
$this->assertSame($hasH3, curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3));
76+
$this->assertSame($hasH3 && defined('CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256'), curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3ONLY));
77+
}
78+
6779
public static function ucFirstDataProvider(): array
6880
{
6981
return [

0 commit comments

Comments
 (0)