12 use http\Message\Parser;
14 foreach (glob(__DIR__."/data/message_*.txt") as $file) {
17 $fd = fopen($file, "r") or die("Could not open $file");
19 switch ($parser->parse(fgets($fd), 0, $message)) {
20 case Parser::STATE_DONE:
21 $string = (string) $message;
23 case Parser::STATE_FAILURE:
24 throw new Exception(($e = error_get_last()) ? $e["message"] : "Could not parse $file");
29 $s = ["START", "HEADER", "HEADER_DONE", "BODY", "BODY_DUMB", "BODY_LENGTH", "BODY_CHUNK", "BODY_DONE", "UPDATE_CL", "DONE"];
30 printf("Unexpected state: %s (%s)\n", $s[$parser->getState()], $file);
37 switch ($parser->stream($fd, 0, $message)) {
38 case Parser::STATE_DONE:
39 case Parser::STATE_START:
42 printf("Expected parser state 0 or 8, got %d", $parser->getState());
44 if ($string !== (string) $message) {
45 $a = explode("\n", $string);
46 $b = explode("\n", (string) $message);
48 $aa = array_shift($a);
49 $bb = array_shift($b);
51 isset($aa) and printf("-- %s\n", $aa);
52 isset($bb) and printf("++ %s\n", $bb);