release 2.4.0
[m6w6/ext-http] / tests / headerparser001.phpt
1 --TEST--
2 header parser
3 --SKIPIF--
4 <?php
5 include "skipif.inc";
6 ?>
7 --FILE--
8 <?php
9 echo "Test\n";
10
11 $headers = array(
12 "One: ","header\n",
13 "Two: header\n\tlines\n",
14 "Three",": header\n lines\n here\n",
15 "More: than one header\n",
16 "More: ", "than: ", "you: ", "expect\n",
17 "\n",
18 );
19
20 $states = array(-1=>"FAILURE",0=>"START","KEY","VALUE","VALUE_EX","HEADER_DONE","DONE");
21 $parser = new http\Header\Parser;
22 do {
23 $state = $parser->parse($part = array_shift($headers),
24 $headers ? 0 : http\Header\Parser::CLEANUP,
25 $result);
26 printf("%2\$-32s | %1\$s\n", $states[$state], addcslashes($part, "\r\n\t\0"));
27 } while ($headers && $state !== http\Header\Parser::STATE_FAILURE);
28
29 var_dump($result);
30
31 ?>
32 ===DONE===
33 --EXPECT--
34 Test
35 One: | VALUE
36 header\n | VALUE_EX
37 Two: header\n\tlines\n | VALUE_EX
38 Three | KEY
39 : header\n lines\n here\n | VALUE_EX
40 More: than one header\n | VALUE_EX
41 More: | VALUE
42 than: | VALUE
43 you: | VALUE
44 expect\n | VALUE_EX
45 \n | DONE
46 array(4) {
47 ["One"]=>
48 string(6) "header"
49 ["Two"]=>
50 string(12) "header lines"
51 ["Three"]=>
52 string(17) "header lines here"
53 ["More"]=>
54 array(2) {
55 [0]=>
56 string(15) "than one header"
57 [1]=>
58 string(17) "than: you: expect"
59 }
60 }
61 ===DONE===