Skip to content

Commit c968691

Browse files
author
Sjoerd Langkemper
committed
Add another test for chunked encoding
1 parent 631c366 commit c968691

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
--TEST--
2+
Chunked encoding
3+
--SKIPIF--
4+
<?php
5+
$filters = stream_get_filters();
6+
if(! in_array( "dechunk", $filters )) die( "skip Chunked filter not available." );
7+
?>
8+
--INI--
9+
allow_url_fopen=1
10+
--FILE--
11+
<?php
12+
13+
final class Splitter extends php_user_filter {
14+
public static int $chunkSize;
15+
function filter($in, $out, &$consumed, $closing): int {
16+
while ($bucket = stream_bucket_make_writeable($in)) {
17+
$head = substr($bucket->data, 0, self::$chunkSize);
18+
$head_bucket = stream_bucket_new($this->stream, $head);
19+
stream_bucket_append($out, $head_bucket);
20+
21+
$tail = substr($bucket->data, self::$chunkSize);
22+
$tail_bucket = stream_bucket_new($this->stream, $tail);
23+
stream_bucket_append($out, $tail_bucket);
24+
25+
$consumed += strlen($bucket->data);
26+
return PSFS_PASS_ON;
27+
}
28+
return PSFS_FEED_ME;
29+
}
30+
}
31+
stream_filter_register("Splitter", "Splitter");
32+
33+
$testdata = "2;key=value\r\nte\r\n2\r\nst\r\n0\r\nTrailer: section\r\n\r\n";
34+
for ($i = 1; $i < strlen($testdata); $i++) {
35+
Splitter::$chunkSize = $i;
36+
37+
$fp = fopen("data:text/plain,$testdata", "r");
38+
stream_filter_append($fp, "Splitter", STREAM_FILTER_READ);
39+
stream_filter_append($fp, "dechunk", STREAM_FILTER_READ);
40+
41+
var_dump(stream_get_contents($fp));
42+
fclose($fp);
43+
}
44+
?>
45+
--EXPECT--
46+
string(4) "test"
47+
string(4) "test"
48+
string(4) "test"
49+
string(4) "test"
50+
string(4) "test"
51+
string(4) "test"
52+
string(4) "test"
53+
string(4) "test"
54+
string(4) "test"
55+
string(4) "test"
56+
string(4) "test"
57+
string(4) "test"
58+
string(4) "test"
59+
string(4) "test"
60+
string(4) "test"
61+
string(4) "test"
62+
string(4) "test"
63+
string(4) "test"
64+
string(4) "test"
65+
string(4) "test"
66+
string(4) "test"
67+
string(4) "test"
68+
string(4) "test"
69+
string(4) "test"
70+
string(4) "test"
71+
string(4) "test"
72+
string(4) "test"
73+
string(4) "test"
74+
string(4) "test"
75+
string(4) "test"
76+
string(4) "test"
77+
string(4) "test"
78+
string(4) "test"
79+
string(4) "test"
80+
string(4) "test"
81+
string(4) "test"
82+
string(4) "test"
83+
string(4) "test"
84+
string(4) "test"
85+
string(4) "test"
86+
string(4) "test"
87+
string(4) "test"
88+
string(4) "test"
89+
string(4) "test"
90+
string(4) "test"
91+
string(4) "test"

0 commit comments

Comments
 (0)