Skip to content

Commit 0f52bfb

Browse files
committed
tests(ext-curl): fix HTTP/2 Server Push tests
1 parent da3ce60 commit 0f52bfb

File tree

6 files changed

+97
-12
lines changed

6 files changed

+97
-12
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Setup Caddy server
2+
runs:
3+
using: composite
4+
steps:
5+
- shell: bash
6+
run: |
7+
sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https
8+
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
9+
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
10+
sudo apt-get update
11+
sudo apt-get install -y caddy
12+
13+
sudo caddy start --config ext/curl/tests/Caddyfile

.github/workflows/push.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
uses: ./.github/actions/setup-mssql
4040
- name: Create Oracle container
4141
uses: ./.github/actions/setup-oracle
42+
- name: Setup Caddy server
43+
uses: ./.github/actions/setup-caddy
4244
- name: apt
4345
uses: ./.github/actions/apt-x64
4446
- name: ccache
@@ -63,13 +65,17 @@ jobs:
6365
uses: ./.github/actions/setup-x64
6466
- name: Test
6567
uses: ./.github/actions/test-linux
68+
env:
69+
RUN_CADDY_TESTS: "1"
6670
- name: Test Tracing JIT
6771
uses: ./.github/actions/test-linux
6872
with:
6973
runTestsParameters: >-
7074
-d zend_extension=opcache.so
7175
-d opcache.enable_cli=1
7276
-d opcache.jit_buffer_size=16M
77+
env:
78+
RUN_CADDY_TESTS: "1"
7379
- name: Verify generated files are up to date
7480
uses: ./.github/actions/verify-generated-files
7581
LINUX_X32:

ext/curl/tests/Caddyfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
admin off
3+
auto_https disable_redirects
4+
}
5+
6+
localhost
7+
8+
# HTTP/2 Server Push
9+
respond /serverpush "main response"
10+
respond /serverpush/pushed "pushed response"
11+
push /serverpush /serverpush/pushed

ext/curl/tests/bug76675.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
Bug #76675 (Segfault with H2 server push write/writeheader handlers)
33
--EXTENSIONS--
44
curl
5-
--XFAIL--
6-
http2.golang.org/serverpush is gone
75
--SKIPIF--
86
<?php
9-
if (getenv("SKIP_ONLINE_TESTS")) {
10-
die("skip online test");
7+
if (!getenv("RUN_CADDY_TESTS")) {
8+
die("skip test needing Caddy");
119
}
1210
$curl_version = curl_version();
1311
if ($curl_version['version_number'] < 0x073d00) {
1412
exit("skip: test may crash with curl < 7.61.0");
1513
}
16-
die("skip test is slow due to timeout, and XFAILs anyway");
1714
?>
1815
--FILE--
1916
<?php
@@ -30,7 +27,7 @@ $mh = curl_multi_init();
3027
curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
3128
curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback);
3229
$ch = curl_init();
33-
curl_setopt($ch, CURLOPT_URL, 'https://http2.golang.org/serverpush');
30+
curl_setopt($ch, CURLOPT_URL, 'https://localhost/serverpush');
3431
curl_setopt($ch, CURLOPT_HTTP_VERSION, 3);
3532
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
3633
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

ext/curl/tests/bug77535.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
Bug #77535 (Invalid callback, h2 server push)
33
--EXTENSIONS--
44
curl
5-
--XFAIL--
6-
http2.golang.org/serverpush is gone
75
--SKIPIF--
86
<?php
9-
if (getenv("SKIP_ONLINE_TESTS")) {
10-
die("skip online test");
7+
if (!getenv("RUN_CADDY_TESTS")) {
8+
die("skip test needing Caddy");
119
}
1210
$curl_version = curl_version();
1311
if ($curl_version['version_number'] < 0x073d00) {
1412
exit("skip: test may crash with curl < 7.61.0");
1513
}
16-
die("skip test is slow due to timeout, and XFAILs anyway");
1714
?>
1815
--FILE--
1916
<?php
@@ -36,7 +33,7 @@ class MyHttpClient
3633
curl_setopt($this->curl, CURLOPT_HEADER, false);
3734
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, false);
3835
curl_setopt($this->curl, CURLOPT_FAILONERROR, false);
39-
curl_setopt($this->curl, CURLOPT_URL, 'https://http2.golang.org/serverpush');
36+
curl_setopt($this->curl, CURLOPT_URL, 'https://localhost/serverpush');
4037
curl_setopt($this->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
4138
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, function ($ch, $data) {
4239
return \strlen($data);

ext/curl/tests/curl_pushfunction.phpt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
Test CURLMOPT_PUSHFUNCTION
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php
7+
if (!getenv("RUN_CADDY_TESTS")) {
8+
die("skip test needing Caddy");
9+
}
10+
$curl_version = curl_version();
11+
if ($curl_version['version_number'] < 0x073d00) {
12+
exit("skip: test may crash with curl < 7.61.0");
13+
}
14+
?>
15+
--FILE--
16+
<?php
17+
$callback = function($parent_ch, $pushed_ch, array $headers) use (&$transfers) {
18+
return CURL_PUSH_OK;
19+
};
20+
21+
$mh = curl_multi_init();
22+
23+
curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
24+
curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback);
25+
26+
$ch = curl_init();
27+
curl_setopt($ch, CURLOPT_URL, "https://localhost/serverpush");
28+
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
29+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
30+
31+
curl_multi_add_handle($mh, $ch);
32+
33+
$responses = [];
34+
$active = null;
35+
do {
36+
$status = curl_multi_exec($mh, $active);
37+
38+
do {
39+
$info = curl_multi_info_read($mh);
40+
if (false !== $info && $info['msg'] == CURLMSG_DONE) {
41+
$handle = $info['handle'];
42+
if ($handle !== null) {
43+
$transfers--;
44+
$responses[] = curl_multi_getcontent($info['handle']);
45+
curl_multi_remove_handle($mh, $handle);
46+
curl_close($handle);
47+
}
48+
}
49+
} while ($info);
50+
} while (count($responses) !== 2);
51+
52+
curl_multi_close($mh);
53+
54+
sort($responses);
55+
print_r($responses);
56+
--EXPECT--
57+
Array
58+
(
59+
[0] => main response
60+
[1] => pushed response
61+
)

0 commit comments

Comments
 (0)