Skip to content

Commit f167b06

Browse files
committed
Added test for #77535 fix
1 parent 97f9fd6 commit f167b06

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

ext/curl/tests/bug77535.phpt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
--TEST--
2+
Bug #77535 (Invalid callback, h2 server push)
3+
--SKIPIF--
4+
<?php
5+
include 'skipif.inc';
6+
if (getenv("SKIP_ONLINE_TESTS")) {
7+
die("skip online test");
8+
}
9+
$curl_version = curl_version();
10+
if ($curl_version['version_number'] < 0x073d00) {
11+
exit("skip: test may crash with curl < 7.61.0");
12+
}
13+
?>
14+
--FILE--
15+
<?php
16+
class MyHttpClient
17+
{
18+
private $mh;
19+
private $curl;
20+
21+
public function sendRequest()
22+
{
23+
if (false === $this->mh = curl_multi_init()) {
24+
throw new \RuntimeException('Unable to create a new cURL multi handle');
25+
}
26+
27+
$this->addServerPushCallback();
28+
29+
$this->curl = curl_init();
30+
curl_setopt($this->curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
31+
curl_setopt($this->curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
32+
curl_setopt($this->curl, CURLOPT_HEADER, false);
33+
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, false);
34+
curl_setopt($this->curl, CURLOPT_FAILONERROR, false);
35+
curl_setopt($this->curl, CURLOPT_URL, 'https://http2.golang.org/serverpush');
36+
curl_setopt($this->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
37+
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, function ($ch, $data) {
38+
return \strlen($data);
39+
});
40+
curl_setopt($this->curl, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
41+
return \strlen($data);
42+
});
43+
curl_multi_add_handle($this->mh, $this->curl);
44+
45+
$stillRunning = null;
46+
while (true) {
47+
do {
48+
$mrc = curl_multi_exec($this->mh, $stillRunning);
49+
} while (CURLM_CALL_MULTI_PERFORM === $mrc);
50+
51+
$info = curl_multi_info_read($this->mh);
52+
while (false !== $info && $info['msg'] == CURLMSG_DONE) {
53+
if (CURLMSG_DONE !== $info['msg']) {
54+
continue;
55+
}
56+
die("Start handle request.");
57+
}
58+
}
59+
}
60+
61+
private function addServerPushCallback(): void
62+
{
63+
64+
$callback = static function () {
65+
return CURL_PUSH_OK;
66+
};
67+
68+
curl_multi_setopt($this->mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
69+
curl_multi_setopt($this->mh, CURLMOPT_PUSHFUNCTION, $callback);
70+
}
71+
}
72+
73+
$buzz = new MyHttpClient();
74+
$buzz->sendRequest();
75+
--EXPECT--
76+
Start handle request.
77+

0 commit comments

Comments
 (0)